0% found this document useful (0 votes)
47 views14 pages

Linked List

The document discusses linked lists, a dynamic data structure used to store and manipulate collections of elements. It describes the advantages of linked lists, including dynamic size and efficient memory utilization. It also discusses the disadvantages, such as increased memory overhead and slower random access. The document then provides examples of operations on linked lists like insertion, deletion, and traversal. It includes algorithms and code examples for performing these operations.
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)
47 views14 pages

Linked List

The document discusses linked lists, a dynamic data structure used to store and manipulate collections of elements. It describes the advantages of linked lists, including dynamic size and efficient memory utilization. It also discusses the disadvantages, such as increased memory overhead and slower random access. The document then provides examples of operations on linked lists like insertion, deletion, and traversal. It includes algorithms and code examples for performing these operations.
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/ 14

Linked List DataStructure

in c
A linked list is a dynamic data structure used to store and manipulate collections
of elements. Learn about their advantages, disadvantages, and how they're useful
in programming.

NAME:-Basir Khan
Regd:-220301120209
Sec:-D
Contents:-

Types Of Linked List

Advantages and Disadvantages

Application of Linked List

Opertaions on Linked List

Algoritm, code exmaples and conclusion


Introduction to Linked List
A linked list is a data structure which can change during
execution.
• Successive elements are connected by pointers.
• Last element points to NULL.
• It can grow or shrink in size during execution of a
program.
• It can be made just as long as required.
• It does not waste memory space.
head

A B C
Types of Linked List
Singly Linked List

A linked list where each node contains a reference to the next node in the list.

Doubly Linked List

A linked list where each node contains references to both the next and previous nodes in the list.

Circular Linked List

A linked list where the last node in the list points back to the first node, forming a loop.
Types of Linked List Circular
Linked
List
head

A B C
Doubly
Linked
List

head tail

A B C
Advantages and Disadvantages of
Linked List

1 Advantages of linked list 2 Disadvantages of linked list

Dynamic size, efficient memory Increased memory overhead due to


utilization, easy insertion/deletion, and storing pointers, slower random access,
flexibility in data storage. and additional complexity in
implementation.
Applications of Linked List

Real-life examples of linked list Where linked lists are used

A music playlist, where each song is connected Task management applications that keep track
to the next song. of to-do lists or project tasks.
Operations on Linked List
1 Insertion

Add a new node to the linked list at a specified position or at the beginning/end of
the list.

2 Deletion

Remove a node from the linked list at a specified position or based on a given value.

3 Traversal

Visit each node in the linked list in a sequential manner and perform operations on
the data.
Algoritm’s and examples

Traversal in Singly Linked List Traversal in Circular Linked List

struct Node void linkedlistTraversal(struct Node *head){


{ struct Node *ptr=head;
int data; do{
struct Node *next; printf("Element: %d\n",ptr->data);
}; ptr=ptr->next;
int display(struct Node *ptr){ }while (ptr!=head);
while(ptr!=NULL){
printf("Element: %d\n",ptr->data);
ptr=ptr->next; }
}
}
Algoritm’s and examples
Insert at first in Linked List Insert At a index in Linked List

struct Node * insertAtFirst(struct Node *head,int data){ struct Node *insertAtIndex(struct Node *head,int
struct Node *ptr = (struct Node *)malloc(sizeof(struct data,int index){
Node)); struct Node *ptr = (struct Node *)malloc(sizeof(struct
ptr->data=data; Node));
ptr->next=head; struct Node *p = head;
return ptr; int i =0;
} while (i!=index-1)
{
p=p->next;
Insert after a node in Linked List i++;
}
struct Node *insertAfterNode(struct Node *head,struct Node ptr->data=data;
*prevNode,int data){ ptr->next=p->next;
struct Node *ptr =(struct Node *)malloc(sizeof(struct p->next=ptr;
Node)); return head;
ptr->data=data;
ptr->next=prevNode->next; }
prevNode->next=ptr;
return head;
}
Algoritm’s and examples

Insert after a node in linked list Insert at end in Linked List

struct Node *insertAfterNode(struct Node *head,struct struct Node *insertAtEnd(struct Node *head,int data){
Node *prevNode,int data){ struct Node *ptr =(struct Node *)malloc(sizeof(struct
struct Node *ptr =(struct Node *)malloc(sizeof(struct Node));
Node)); ptr->data=data;
ptr->data=data; struct Node *p = head;
ptr->next=prevNode->next; while(p->next!=NULL){
prevNode->next=ptr; p=p->next;
return head; }
} p->next=ptr;
ptr->next=NULL;
return head;
}
Algoritm’s and examples
Delete at first in Linked List Delete end node in Linked List

struct Node *deleteFirst(struct Node *head){ struct Node *deleteEnd(struct Node *head){
struct Node *p = head; struct Node *p= head;
head =head->next; struct Node *q =head->next;
free(p); while(q->next!=NULL){
return head; p=p->next; Delete Given Key in Linked List
} q=q->next;
} struct Node *deleteAtGivenKey(struct Node *head,int
Delete at index in Linked List p->next=NULL; value){
free(q); struct Node *p =head;
return head; struct Node *q =head->next;
struct Node *deleteAtIndex(struct Node *head,int index){ while(q->data!=value&&q->next!=NULL){
struct Node *p = head; }
p=p->next;
struct Node *q = head->next; q=q->next;
for(int i =0;i<index-1;i++){ }
p=p->next; if(q->data==value){
q=q->next; p->next=q->next;
} free(q);
p->next=q->next; return head;
free(q); }
return head; }
}
Conclusion and Summary

The power of linked lists

Linked lists provide a flexible data structure for efficient manipulation, making them
indispensable in various applications.

You might also like