0% found this document useful (0 votes)
34 views18 pages

Ece532 Chapter 2.3 Linked List P2

Linked list

Uploaded by

Husna Nuna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views18 pages

Ece532 Chapter 2.3 Linked List P2

Linked list

Uploaded by

Husna Nuna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

ECE 532

CHAPTER 2: FUNDAMENTAL DATA


STRUCTURES: LINKED LIST (SINGLY-LINKED
LIST PART 2)
Lecturer: Dr. Roslina Mohamad
Room: Tower 2, Level 13, No:14C

1
Learning Outcomes
At the end of this lecture, you will be able to:
• Learn about linked lists
• Become aware of the basic properties of
linked lists
• Explore the insertion and deletion
operations on linked lists
• Discover how to build and manipulate a
linked list

2
Linked List Operations
Basic operations:
• add a node to the end of the list
• insert a node within the list
• traverse the linked list
• Delete/remove a node from the list
• delete/destroy the list

3
Singly-linked list. Removal (deletion) operation

There are four cases:


• Remove node when list have only one node
• Remove first node
• Remove last node
• Remove in between node
List has only one node
• When list has only one node, which is indicated by the
condition (head ==tail), the removal is quite simple. Algorithm
disposes the node, pointed by head (or tail) and sets both head
and tail to NULL

//See Example 2.21


REMOVE FIRST NODE
In this case, first node (current head node) is removed from
the list.
Remove First Node
• It can be done in two steps:
• Update head link to point to the node, next to
the head.
REMOVE FIRST NODE
 Dispose removed node.

//See Example 2.22


9
Remove Last Node
• In this case, last node (current tail node) is removed from the
list. This operation is a bit more tricky, than removing the first
node, because algorithm should find a node, which is previous
to the tail first.
Remove Last Node
It can be done in three steps:
Update tail link to point to the node, before the tail. In
order to find it, list should be traversed first,
beginning from the head.
Remove Last Node
• Set next link of the new tail to NULL
Remove Last Node
Dispose removed node.

//See Example 2.23


Remove in between Node
In general case, node to be removed is always located
between two list nodes. Head and tail links are not
updated in this case.
Remove in between Node

 Such a removal can be done in two steps:


 Update next link of the previous node, to
point to the next node, relative to the
removed node.
Remove in between Node
• Dispose removed node.

//See Example 2.24


Variations of the Linked List
Other linked list organizations:
◦ doubly-linked list: each node contains two pointers:
one to the next node in the list, one to the previous
node in the list

5 13 19 NULL

list
head NULL

17
-
17
17-18

Variations of the Linked List


Other linked list organizations:
• circular linked list: the last node in the list points back to the first
node in the list, not to NULL

5 13 19

list
head

You might also like