Seminar On Linked List
Seminar On Linked List
Presented by
Joydip Ghosh
3rd Year Roll-08
Department of Information Technology
Academy Of Technology
Joydip Ghosh (Academy Of Technology)
What is Linked-List
myList
a b c d
NULL
This is the most basic type of linked list, with each node containing a
single pointer, to the next node.
Head
Multi linked list
NULL
More advanced than the single linked list, each node may be
connected to many other nodes.
Head
Special case : Doubly linked lists
Circular linked list
With a circular linked list, the last node is connected to the first,
to form a circle. Joydip Ghosh (Academy Of Technology)
MULTI
MULTI OR
OR DOUBLY
DOUBLY LINKED
LINKED
LIST
LIST
In computer science, a doubly-linked list is a linked
data structure that consists of a set of data records,
each having two special link fields that
contain references to the previous and to the next
record in the sequence. It can be viewed as two singly-
linked lists formed from the same data items, in two
opposite orders.
A
Creation
Creation Of
Of Single
Single Node
Node
NULL
NULL
X
head
typedef struct dnode
{
struct dnode *prev;
int data;
struct dnode *next;
}dn;
x=(dn*)malloc(sizeof(dn));
x->prev=x->next=NULL;
*head=x;
head tail
// constructor
DoubleList()
{
head = new DoubleListNode ();
tail = new DoubleListNode ();
head->next = tail;
tail->prev = head;
}
Joydip Ghosh (Academy Of Technology)
Inserting into a Doubly Linked List
a c
head tail
current
a c
head b tail
current
a c
head b tail
current
a c
head b tail
current
a c
head b tail
current
a c
head b tail
current
a c
head b tail
current
a c
head b
current
oldNode=current;
oldNode->prev->next = oldNode->next;
oldNode->next->prev = oldNode->prev;
current = oldNode->prev;
delete oldNode; Joydip Ghosh (Academy Of Technology)
Deleting
Deleting an
an element
element from
from aa double
double linked
linked list
list
a c
head b
current
oldNode
oldNode=current;
oldNode->prev->next = oldNode->next;
oldNode->next->prev = oldNode->prev;
current = oldNode->prev;
delete oldNode;
Joydip Ghosh (Academy Of Technology)
Deleting an element from a double linked
list
a c
head b
current oldNode
oldNode=current;
oldNode->prev->next = oldNode->next;
oldNode->next->prev = oldNode->prev;
current = oldNode->prev;
delete oldNode; Joydip Ghosh (Academy Of Technology)
Deleting an element from a double linked
list
a c
head b
current oldNode
oldNode=current;
oldNode->prev->next = oldNode->next;
oldNode->next->prev = oldNode->prev;
current = oldNode->prev;
delete oldNode; Joydip Ghosh (Academy Of Technology)
Deleting an element from a double linked
list
a c
head b
current oldNode
oldNode=current;
oldNode->prev->next = oldNode->next;
oldNode->next->prev = oldNode->prev;
current = oldNode->prev;
delete oldNode;
Joydip Ghosh (Academy Of Technology)
Deleting an element from a double linked
list
a c
head
current
oldNode=current;
oldNode->prev->next = oldNode->next;
oldNode->next->prev = oldNode->prev;
current = oldNode->prev;
delete oldNode;
Joydip Ghosh (Academy Of Technology)
DLLs
DLLs compared
compared to
to
SLLs
SLLs
Advantages: Disadvantages:
• Can be traversed in • Requires more
either direction space
(may be essential • List manipulations
for some programs) are slower
(because more
• Some operations, links must be
such as deletion and changed)
inserting before a • Greater chance of
node, become easier having bugs
Joydip Ghosh (Academy Of Technology) (because more
Circularly
Circularly Linked
Linked Lists
Lists
aList
size 3 head
21 24 47
21 24 47
q p q p
Node p = head, q; p
while (p.getNext( ) != head && p.getData( ) != x) {
q = p;
p = p.getNext( );
Joydip Ghosh (Academy Of Technology)
}
A circularly-linked list with a single Node
Special case – List contains a
aList
single Node
4
5
FOR
FORNODES
NODESNO
NO ==55
Joydip Ghosh (Academy Of Technology) FOR
FORCOUNT
COUNT==33
Joydip Ghosh (Academy Of Technology)