1 / 36

Linked List

Linked List. Data Structures (TIB11) IT Department – Bunda Mulia University Teady Matius, M.Kom tmulyana@bundamulia.ac.id. Objectives. To understand about linked list To understand about the operations of linked list To understand about the common variants of linked list. Pointer.

holland
Download Presentation

Linked List

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linked List Data Structures (TIB11) IT Department – Bunda Mulia University Teady Matius, M.Kom tmulyana@bundamulia.ac.id

  2. Objectives • To understand about linked list • To understand about the operations of linked list • To understand about the common variants of linked list Data Structures - Linked List

  3. Pointer • A pointer is basically used to represent the relation between two cells. Example : Pointer A to B Data Structures - Linked List

  4. Pointer - example (Example from wikipedia) • Pointer a pointing to variable b. Note that b stores a number, where a stores the address of b in memory (1462) Data Structures - Linked List

  5. Linked List • A finite sequence of elements s1, s2, ....., sn • Node : every recorded that contains information and linked to other node • Linked List elements • Information • link: linked to other node Data Structures - Linked List

  6. Two important variables • Head: contains the information of first node address pointer • CurrentCell / PointerCell: contains the information of the current node address pointer that being accessed Data Structures - Linked List

  7. Remember!!! • Head is the most important information to direct your linked list • With the ‘Head’ you can go to the first node, and move toward to the destination node • When you lose the ‘Head’ it means you lose your linked list too • Never ever lose your ‘HEAD’!!! Data Structures - Linked List

  8. Single Linked List Data Structures - Linked List

  9. Linked List Operation • Search / Locate • Insert • After the current cell • Before the current cell • Delete Data Structures - Linked List

  10. Possible Operations • At the front of list • At the middle of list • At the end of list Data Structures - Linked List

  11. Locate Operation • Assign PointerCell as Head PointerCell = Head; • Move toward by directing the PointerCell to the next PointerCell until find the matched node. PointerCell = PointerCell->Next; Data Structures - Linked List

  12. Data Structures - Linked List

  13. Insert Operation • At the front of list Can be happen only at insert before current cell • At the end of list Can be happen only at insert after current cell • At the middle of list Data Structures - Linked List

  14. Insert at the front • Make new node • Fill information at the new node • direct next link to the head node • Set head pointer to the new node

  15. Insert at the front (cont.) Data Structures - Linked List

  16. Insert at the middle - after current cell • Create new node • Fill information to the new node • Copy next link current node to the next link new node • Set next link at the current node to the new node

  17. Insert at the middle - after current cell (cont.) Data Structures - Linked List

  18. Insert at the middle - before current cell Note: You need to get the previous node address first!!! • Create new node • Fill information to the new node • Locating previous node • Copy next link previous node to the next link new node • Set next link at the previous node to the new node

  19. Insert at the middle - before current cell (cont.) Data Structures - Linked List

  20. Locating previous next Can be done in many ways • Save the previous node when locating the current node PreviousNode = CurrentNode; CurrentNode = CurrentNode->Next; • Retrieve when needed RetrieveNode = HeadNode; While (RetrieveNode-> != CurrentNode) { RetrieveNode = RetrieveNode->Next; } PreviousNode = RetrieveNode; • Use double list; directing previous node with previous link pointer.

  21. Insert at the end • Create new node • Fill the information at the new node • Set next node new node as NULL • Directing next link at the last node or tail to the new node

  22. Insert at the end (cont.) Data Structures - Linked List

  23. Delete Operation • At the front – delete head (REMEMBER: don’t until lose the head!) • At the middle • At the end – delete tail Data Structures - Linked List

  24. Delete Head (1st trick) Data Structures - Linked List

  25. Delete Head (2nd trick)

  26. Delete Head (3rd trick)

  27. Delete Middle Data Structures - Linked List

  28. Delete Tail Data Structures - Linked List

  29. Common Variants of Linked List • Single Linked List • Double Linked List • Circular Linked List • Multilevel List Data Structures - Linked List

  30. Doubled Linked List • Each node has two Link • Previous Link pointed to the previous node • Next Link pointed to th next node • Head  Prev Link Pointed as NULL • Tail  Next Link Pointed as NULL Data Structures - Linked List

  31. Circular Linked List • Next pointer at the tail, pointed to the Head Data Structures - Linked List

  32. What your opinion about double circular list?

  33. Multilevel List • List act as group list which node act as parent of groups have extra link to pointed to the other list as child list beside the link to the next group list node. • Element • Information • Link to other node parent node • Link to child list Data Structures - Linked List

  34. Multilevel List Element

  35. Example of multilevel list

  36. references • http://courses.cs.vt.edu/~csonline/DataStructures/Lessons/index.html • http://www.cs.sunysb.edu/%7Eskiena/214/lectures/index.html • http://www.site.uottawa.ca/%7Eholte/T26/lecture1.html • Drozdek, Adam. Data Structures And Algorithms In C++ 3rd ed. Thomson Course Technology. 2005. • Chai, Ian. White, Jonathon D. Structuring Data And Building Algorithms. Mc Graw Hill. 2006. • Reingold, Edward M. Hansen Wilfred J. Data Structures. Little, Brown and Company. 1983. Data Structures - Linked List

More Related