36
Linked List Data Structures (TIB11) IT Department – Bunda Mulia University Teady Matius, M.Kom [email protected]

Linked List

  • Upload
    holland

  • View
    75

  • Download
    1

Embed Size (px)

DESCRIPTION

Linked List. Data Structures (TIB11) IT Department – Bunda Mulia University Teady Matius, M.Kom [email protected]. Objectives. To understand about linked list To understand about the operations of linked list To understand about the common variants of linked list. Pointer. - PowerPoint PPT Presentation

Citation preview

Page 1: Linked List

Linked List

Data Structures (TIB11)IT Department – Bunda Mulia University

Teady Matius, [email protected]

Page 2: Linked List

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 2

Page 3: Linked List

Pointer

• A pointer is basically used to represent the relation between two cells.

Example : Pointer A to B

Data Structures - Linked List 3

Page 4: Linked List

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 4

Page 5: Linked List

Linked List

• A finite sequence of elementss1, 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 5

Page 6: Linked List

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 6

Page 7: Linked List

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 7

Page 8: Linked List

Single Linked List

Data Structures - Linked List 8

Page 9: Linked List

Linked List Operation

• Search / Locate• Insert– After the current cell– Before the current cell

• Delete

Data Structures - Linked List 9

Page 10: Linked List

Possible Operations

• At the front of list • At the middle of list• At the end of list

Data Structures - Linked List 10

Page 11: Linked List

Locate Operation

• Assign PointerCell as HeadPointerCell = Head;

• Move toward by directing the PointerCell to the next PointerCell until find the matched node.PointerCell = PointerCell->Next;

Data Structures - Linked List 11

Page 12: Linked List

Data Structures - Linked List 12

Page 13: Linked List

Insert Operation

• At the front of list Can be happen only at insert before current cell

• At the end of listCan be happen only at insert after current cell

• At the middle of list

Data Structures - Linked List 13

Page 14: Linked List

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

Page 15: Linked List

Insert at the front (cont.)

Data Structures - Linked List 15

Page 16: Linked List

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

Page 17: Linked List

Insert at the middle - after current cell (cont.)

Data Structures - Linked List 17

Page 18: Linked List

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

Page 19: Linked List

Insert at the middle - before current cell (cont.)

Data Structures - Linked List 19

Page 20: Linked List

Locating previous nextCan be done in many ways• Save the previous node when locating the current node

PreviousNode = CurrentNode;CurrentNode = CurrentNode->Next;

• Retrieve when neededRetrieveNode = HeadNode;While (RetrieveNode-> != CurrentNode){

RetrieveNode = RetrieveNode->Next;}PreviousNode = RetrieveNode;

• Use double list; directing previous node with previous link pointer.

Page 21: Linked List

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

Page 22: Linked List

Insert at the end (cont.)

Data Structures - Linked List 22

Page 23: Linked List

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 23

Page 24: Linked List

Delete Head (1st trick)

Data Structures - Linked List 24

Page 25: Linked List

Delete Head (2nd trick)

Page 26: Linked List

Delete Head (3rd trick)

Page 27: Linked List

Delete Middle

Data Structures - Linked List 27

Page 28: Linked List

Delete Tail

Data Structures - Linked List 28

Page 29: Linked List

Common Variants of Linked List

• Single Linked List• Double Linked List• Circular Linked List• Multilevel List

Data Structures - Linked List 29

Page 30: Linked List

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 30

Page 31: Linked List

Circular Linked List

• Next pointer at the tail, pointed to the Head

Data Structures - Linked List 31

Page 32: Linked List

What your opinion about double circular list?

Page 33: Linked List

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 33

Page 34: Linked List

Multilevel List Element

Page 35: Linked List

Example of multilevel list

Page 36: Linked List

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 36