Presentation is loading. Please wait.

Presentation is loading. Please wait.

IT Department – Bunda Mulia University

Similar presentations


Presentation on theme: "IT Department – Bunda Mulia University"— Presentation transcript:

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

2 Data Structures - 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

3 Data Structures - Linked List
Pointer A pointer is basically used to represent the relation between two cells. Example : Pointer A to B In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address. A pointer references a value stored elsewhere in memory, and obtaining or requesting the value to which a pointer refers is called dereferencing the pointer. A pointer is a simple implementation of the general reference data type (although it is quite different from the facility referred to as a reference in C++). Pointers to data improve performance for repetitive operations such as traversing string and tree structures, and pointers to functions are used for binding methods in Object-oriented programming and run-time linking to dynamic link libraries (DLLs). While "pointer" has been used to refer to references in general, it more properly applies to data structures whose interface explicitly allows the pointer to be manipulated as a memory address.[citation needed] Because pointers allow largely unprotected access to memory addresses, there are risks associated with using them. For general information about references, see reference (computer science). Data Structures - Linked List

4 Data Structures - 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

5 Data Structures - 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 Data Structures - 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

8 Data Structures - Linked List
Single Linked List Data Structures - Linked List

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

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

11 Data Structures - Linked List
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 Data Structures - Linked List
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 Data Structures - 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

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

25 Delete Head (2nd trick)

26 Delete Head (3rd trick)

27 Data Structures - Linked List
Delete Middle Data Structures - Linked List

28 Data Structures - Linked List
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 Data Structures - 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

31 Data Structures - Linked List
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 Data Structures - 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

34 Multilevel List Element

35 Example of multilevel list

36 Data Structures - Linked List
references Drozdek, Adam. Data Structures And Algorithms In C++ 3rd ed. Thomson Course Technology Chai, Ian. White, Jonathon D. Structuring Data And Building Algorithms. Mc Graw Hill Reingold, Edward M. Hansen Wilfred J. Data Structures. Little, Brown and Company Data Structures - Linked List


Download ppt "IT Department – Bunda Mulia University"

Similar presentations


Ads by Google