0% found this document useful (0 votes)
222 views27 pages

Seminar On Linked List

The document discusses different types of linked lists including single linked lists, double linked lists, and circular linked lists. It describes the anatomy and implementation of these different linked list structures, including how to insert and delete nodes. The presentation provides information on linked lists to help attendees understand their structure and uses in computer science applications.

Uploaded by

Joydip Ghosh
Copyright
© Attribution Non-Commercial (BY-NC)
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)
222 views27 pages

Seminar On Linked List

The document discusses different types of linked lists including single linked lists, double linked lists, and circular linked lists. It describes the anatomy and implementation of these different linked list structures, including how to insert and delete nodes. The presentation provides information on linked lists to help attendees understand their structure and uses in computer science applications.

Uploaded by

Joydip Ghosh
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 27

SEMINAR ON LINKED LIST

(CIRCULAR AND DOUBLE)

Presented by
Joydip Ghosh
3rd Year Roll-08
Department of Information Technology
Academy Of Technology
Joydip Ghosh (Academy Of Technology)
What is Linked-List

 In computer science, a linked list is a data


structure that consists of a sequence of data
records such that in each record there is
a field that contains a reference (i.e., a link) to
the next record in the sequence.

Joydip Ghosh (Academy Of Technology)


ANATOMY OF LINKED LIST
A linked list consists of:
A sequence of nodes

myList

a b c d

The list have a header


Each node contains a value
and a link (pointer or reference) to some other node
The last node contains a null link

Joydip Ghosh (Academy Of Technology)


TYPES OF LINKED-
Single linked list LIST Head

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.

Joydip Ghosh (Academy Of Technology)


Basic
Basic Structure
Structure Of
Of Double
Double Linked
Linked List
List

data: the user's data


next, prev: the address of the next and previous
node in the list

prev data next

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;

Joydip Ghosh (Academy Of Technology)


Empty Doubly Linked List

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

newNode = new DoublyLinkedListNode()


newNode->prev = current;
newNode->next = current->next;
newNode->prev->next = newNode;
newNode->next->prev = newNode;
current = newNode
Joydip Ghosh (Academy Of Technology)
Inserting into a Doubly Linked List

a c

head b tail
current

newNode = new DoublyLinkedListNode()


newNode->prev = current;
newNode->next = current->next;
newNode->prev->next = newNode;
newNode->next->prev = newNode;
current = newNode
Joydip Ghosh (Academy Of Technology)
Inserting into a Doubly Linked List

a c

head b tail
current

newNode = new DoublyLinkedListNode()


newNode->prev = current;
newNode->next = current->next;
newNode->prev->next = newNode;
newNode->next->prev = newNode;
current = newNode
Joydip Ghosh (Academy Of Technology)
Inserting into a Doubly Linked List

a c

head b tail
current

newNode = new DoublyLinkedListNode()


newNode->prev = current;
newNode->next = current->next;
newNode->prev->next = newNode;
newNode->next->prev = newNode;
current = newNode
Joydip Ghosh (Academy Of Technology)
Inserting into a Doubly Linked List

a c

head b tail
current

newNode = new DoublyLinkedListNode()


newNode->prev = current;
newNode->next = current->next;
newNode->prev->next = newNode;
newNode->next->prev = newNode;
current = newNode
Joydip Ghosh (Academy Of Technology)
Inserting into a Doubly Linked List

a c

head b tail
current

newNode = new DoublyLinkedListNode()


newNode->prev = current;
newNode->next = current->next;
newNode->prev->next = newNode;
newNode->next->prev = newNode;
current = newNode
Joydip Ghosh (Academy Of Technology)
Inserting into a Doubly Linked List

a c

head b tail
current

newNode = new DoublyLinkedListNode()


newNode->prev = current;
newNode->next = current->next;
newNode->prev->next = newNode;
newNode->next->prev = newNode;
current = newNode
Joydip Ghosh (Academy Of Technology)
Deleting an element from a double linked list

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

A circularly-linked list is a singly-linked list


where the last Node refers back to the first
Node in the list. A tail reference is not used.
Joydip Ghosh (Academy Of Technology)
Traversing a circularly-linked list
aList To insertion
An traverse acan circularly-linked
be performed list,
movethe
after a pair
Node ofthat
handles until pos == i
q references,
(or p.getNext(
and a removal will) ==remove
head) the
Node referenced by p, using q to
size 3 head Locate
reattachthe
thenode
list. containing x = 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

The succ field of a single Node


contains a handle to itself
size 1 head

Constructor for Node


public Node(Object obj) {
data = obj;
21
succ = this;
} The object under construction

The only special circumstances about Create a Node referring to itself


adding the first or removing the last and overwrite the succ field using
Node from a circularly-linked list setNext( ) when adding to the list if
Node is not the first Node to be
involve setting the contents of head.
added.
Joydip Ghosh (Academy Of Technology)
APPLICATIONS OF CIRCULAR LINKED
LIST
Jheophus
Problem 2
START 3
1
WINNER

4
5
FOR
FORNODES
NODESNO
NO ==55
Joydip Ghosh (Academy Of Technology) FOR
FORCOUNT
COUNT==33
Joydip Ghosh (Academy Of Technology)

You might also like