DulcetAirman icon

Linked List in SQL

DulcetAirman | PRO | 03/24/17 10:27:36 PM UTC | 0 ⭐ | 734 👁️ | Never ⏰ | []
text |

550 B

|

None

|

0 👍

/

0 👎

Columns of table "linked_list":
unique_id integer (unique) 
list_id integer (indexed)
next_id : integer (FK unique_id)
value : ???
 List [A, B] with id 42:
(1, 42, 2, A)
(2, 42, null, B)
 List [ x,y,z ] with id 123:
(3, 123, 4, x)
(4, 123, 5, y)
(5, 123, null, z)
 Now I insert new value Q between x and y in list 123:
UPDATE: (3, 123, 6, x)
INSERT: (6, 123, 4, Q)
 You know that 1 and 3 are both heads because no other row links to them. 
You know 2 and 5 are last items because they reference null.
An empty list simply has no rows.

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎