0% found this document useful (0 votes)
172 views15 pages

Linked List - SLL

Linked lists are a linear data structure consisting of nodes linked together in a sequence. Each node contains data and a pointer to the next node. Linked lists allow for efficient insertion and deletion of nodes and are used to implement other data structures like stacks, queues, and graphs. There are several types of linked lists including singly linked lists where each node points to the next node, doubly linked lists where each node points to both the next and previous nodes, and circular linked lists where the last node points to the first node. Common operations on linked lists include traversing the list, inserting nodes, and deleting nodes.

Uploaded by

Hashmi Majid
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)
172 views15 pages

Linked List - SLL

Linked lists are a linear data structure consisting of nodes linked together in a sequence. Each node contains data and a pointer to the next node. Linked lists allow for efficient insertion and deletion of nodes and are used to implement other data structures like stacks, queues, and graphs. There are several types of linked lists including singly linked lists where each node points to the next node, doubly linked lists where each node points to both the next and previous nodes, and circular linked lists where the last node points to the first node. Common operations on linked lists include traversing the list, inserting nodes, and deleting nodes.

Uploaded by

Hashmi Majid
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/ 15

Linked List

Linked List
Linked List is a linear data structure and it is very common data structure which consists of group of
nodes in a sequence which is divided in two parts. Each node consists of its own data and the address of
the next node and forms a chain. Linked Lists are used to create trees and graphs.
Advantages and Disadvantages of Linked Lists
There are some basic advantages & disadvantages of Linked Lists are...
Advantages
• They are a dynamic in nature which allocates the memory when required.
• Insertion and deletion operations can be easily implemented.
• Stacks and queues can be easily executed.
• Linked List reduces the access time.
Disadvantages
• The memory is wasted as pointers require extra memory for storage.
• No element can be accessed randomly; it has to access each node sequentially.
• Reverse Traversing is difficult in linked list.
Applications of Linked List
Linked list normally used to implements...
• Linked lists are used to implement stacks, queues, graphs, etc.
• Linked lists let you insert elements at the beginning and end of the list.
• In Linked Lists we don't need to know the size in advance.
Types of Linked List
Singly Linked List
Singly linked lists contain nodes which have a data part as well as an address part i.e. next, which points
to the next node in sequence of nodes. The operations we can perform on singly linked lists are
insertion, deletion and traversal.
Types of Linked List
Doubly Linked List
In a doubly linked list, each node contains two links the first link points to the previous node and the
next link points to the next node in the sequence.
Types of Linked List
Circular Linked List
In the circular linked list the last node of the list contains the address of the first node and forms a
circular chain.
Singly Linked List
Single linked list is a sequence of elements in which every element has link to its next element in the
sequence.
In any single linked list, the individual element is called as "Node". Every "Node" contains two
fields, data and next. The data field is used to store actual value of that node and next field is used to
store the address of the next node in the sequence.

Note
• In a single linked list, the address of the first node is always stored in a reference node known as "front" (Some
times it is also known as "head").
• Always next part (reference part) of the last node must be NULL.
Algorithm to Create a Singly linked List
For creating a singly list we should do the following task
(a) Declaration
(b) Initial Condition
(c) Steps for Algorithms

Declaration Initial Condition


struct node head=null
{ temp=nul
int info; current=null
struct node * next;
} *head,*current,*temp
Declaration
Begin if (head=null)

Step 1 Read the element into x {


head=temp
Step 2 Create a temp node in the
memory current=temp

temp =(struct node )sizeof (node) }


else
Step 3 Assign the values in temp node as
follows {

temp -> info =x current ->next =temp


current ->current ->next
temp ->next=null
}
Step 4 check whether head is null or not
Step 5 follow step 1 to 4 to insert remaining element in the
list.
End
Traverse or Print Elements
void DISPLAY ()
Begin
current=head
while (current != null)
{
Print "current -> info"
current =current ->next
}
End
Insert an Element
Begin
Step 1 Read the element into x
Step 2 Create an temp node in memory as follows
temp=(struct node *)size of (node)
Step 3 Set the values in temp node as follows
temp-> info =x
temp->next=null
Step 4 Search the element after which node will be inserted
current =SEARCH()
Step 5 insert temp node offer current node as follows
temp->next =current -> next
current->next=temp
End
Insert an Element
void display(struct node *r)
{
r=head;
if(r==NULL)
{
return;
}
while(r!=NULL)
{
printf("%d ",r->data);
r=r->next;
}
printf("\n");
}
Insert an Element
int delete(int num) prev->next=temp->next;
{
free(temp);
struct node *temp, *prev;
temp=head;
return 1;
while(temp!=NULL) }
{ }
if(temp->data==num)
else
{
if(temp==head) {
{ prev=temp;
head=temp->next; temp= temp->next;
free(temp);
}
return 1;
} }
else return 0;
{
}

You might also like