Documente Academic
Documente Profesional
Documente Cultură
It can be accessed as
freshnode.data
freshnode.link
LINKED LISTS
OPERATION ON LINKED LIST
The basic operations to be performed on the
linked lists are
• Creation
• Insertion
• Deletion
• Traversing
• Searching
• Display
LINKED LISTS
Creation
Deletion
This operation is used to delete a node from
the linked list. A node may be deleted from
the
• Beginning of a linked list
• End of a linked list
• Specified item in the list
LINKED LISTS
Traversing
Searching
Display
start
10 20 30 40
LINKED LIST
Circular Doubly Linked list
start 10 20 5 15
left data right
• More memory
• If the number of fields are more, then more
memory space is needed
start
20 40 25 48 null
32 null
newnode
LINKED LIST
Inserting a node at the beginning
start
20 40 25 48 null
32
newnode
LINKED LIST
Void insert_at_begin(int item)
{
node newnode=new node(item);
if (start!=null)
newnode.link=start;
start=newnode;
}
LINKED LIST
Inserting a node at the end
start
20 40 25 48 null
32 null
newnode
LINKED LIST
Inserting a node at the end
loc
start
20 40 25 48 null
32 null
newnode
LINKED LIST
Inserting a node at the end
loc
start
20 40 25 48
32 null
newnode
LINKED LIST
Inserting a node at the end
Void insert_at_end(int item)
{ node newnode=new node(item);
loc=start;
while (loc.link!=null)
loc=loc.link;
loc.link=newnode;
}
LINKED LIST
Inserting a new node at the specified
position
start
20 40 25 48 null
32 null
Insert a new node after
the second node newnode
LINKED LIST
Inserting a new node at the specified
position
start
20 40 25 48 null
loc
32 null
newnode
LINKED LIST
Inserting a new node at the specified
position
start
20 40 25 48 null
loc
32
newnode
LINKED LIST
Inserting a new node at the specified
position
Void insert_specific_position(int item, int pos)
{ node newnode= new node(item);
loc=start; temp=1;
while(temp<pos){
loc=loc.link;
temp=temp+1;}
newnode.link=loc.link;
loc.link=newnode;
}
LINKED LIST
Deleting the first node
start
20 40 25 48 null
LINKED LIST
Deleting the first node
start
20 40 25 48 null
LINKED LIST
Deleting the first node
Void delete_firstnode()
{ if (start!= null)
start=start.link;
}
LINKED LIST
Deleting the last node
start
20 40 25 48 null
LINKED LIST
Deleting the last node
prev last
start
20 40 25 48 null
LINKED LIST
Deleting the last node
prev last
start
20 40 25 null 48 null
LINKED LIST
Deleting the last node
Void delete_lastnode()
{ last=start;
while(last.link!=null)
{ prev=last;
last=last.link;
}
prev.link=null;
}
LINKED LIST
Deleting the node containing a particular
item
start
20 40 25 48 null