SHARE
TWEET

Linked List in SQL

DulcetAirman Mar 24th, 2017 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top