Advertisement
DulcetAirman

Linked List in SQL

Mar 24th, 2017
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. Columns of table "linked_list":
  2. unique_id integer (unique)
  3. list_id integer (indexed)
  4. next_id : integer (FK unique_id)
  5. value : ???
  6.  
  7. List [A, B] with id 42:
  8. (1, 42, 2, A)
  9. (2, 42, null, B)
  10.  
  11. List [ x,y,z ] with id 123:
  12. (3, 123, 4, x)
  13. (4, 123, 5, y)
  14. (5, 123, null, z)
  15.  
  16. Now I insert new value Q between x and y in list 123:
  17. UPDATE: (3, 123, 6, x)
  18. INSERT: (6, 123, 4, Q)
  19.  
  20. You know that 1 and 3 are both heads because no other row links to them.
  21. You know 2 and 5 are last items because they reference null.
  22. An empty list simply has no rows.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement