0% found this document useful (0 votes)
10 views

04 Link List

This document discusses linked lists, including their structure, implementation, operations, and variations. It defines a linked list as a data structure made up of nodes that point to the next node in the list. The key operations covered are inserting and deleting nodes at different positions in the list. Variations discussed include circular linked lists, doubly linked lists, and multi lists.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

04 Link List

This document discusses linked lists, including their structure, implementation, operations, and variations. It defines a linked list as a data structure made up of nodes that point to the next node in the list. The key operations covered are inserting and deleting nodes at different positions in the list. Variations discussed include circular linked lists, doubly linked lists, and multi lists.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 56

Data Structures and

Algorithms
Lecture – Linked List

Amir Ali
[email protected]
Outline
Story
Story
Story
Story
Linked List
Linked List
Linked List
Linked List – Implementation
Linked List – Implementation
Linked List – Implementation
struct Node
{
int data;
Node* link;
}

Node * A;

A = NULL ; // empty list

Node* temp = (Node*)malloc(sizeof(Node))


Linked List – Implementation
struct Node
{
int data;
Node* link;
}

Node * A;

A = NULL ; // empty list

Node* temp = (Node*)malloc(sizeof(Node))


(*temp).data = 2;
(*temp).link = NULL:
A= temp;
Linked List – Implementation
struct Node
{
int data;
Node* link;
}

Node * A;

A = NULL ; // empty list

Node* temp = new Node();


Temp-> data = 2;
temp-> link = NULL:
A= temp;
Introduction to Linked List
Linked List – Example

Linked List of Records


Storage Structure of Linked List
Operations of Linked List
Pointer Implementation of Linked List
Pointer Implementation of Linked List
Inserting Node into Linked List
Inserting Node into Linked List
Inserting Node into Linked List

void InsFront (char a[]) {

Node* ptr = new Node();

strcpy (ptr->data,a);

ptr->next = head;

head = ptr;

}
Inserting Node into Linked List
Inserting Node into Linked List

void InsEnd (char a[]) {


Node* temp= new Node();
temp = head;
while(temp->next != NULL)
temp = temp->next;
Node * ptr = new Node();
strcpy(ptr->data,a);
ptr-> next = NULL;
temp-> next = ptr;
}
Inserting Node at nth position
200 100 250
head
2 100 4 250 6 X
200
1 2 3

Insert (data, n)

200 100 250


head
2 100 4 300 6 X
200
1 2 3
300
5 250
Inserting Node at nth position
Inserting Node at nth position
Deleting a Node from Linked List
Deleting a Node from Linked List
Deleting a Node from Linked List

Void del_first()
{
Node* temp = new Node();
temp = head;
head = head->next;
free(temp);
}
Deleting Node at nth position
Deleting Node at nth position
Deleting Node at nth position
Traversing a Linked List
Traversing a Linked List
Sorting a Linked List
Sorting a Linked List
Performance of a Linked List
Performance of a Linked List
Advantages/Disadvantages of a Linked List
Applications of a Linked List
Cursor Implementation of a Linked List
Variations of a Linked List
Variations of a Linked List
Circular Linked List
Advantages/Disadvantages
Doubly Linked List
Basic Operations of Doubly Linked List
Basic Operations of Doubly Linked List
Doubly Linked List – insert at head
Doubly Linked List - Traversing
Advantages/Disadvantages of Doubly Linked List
Circular Doubly Linked List
Multi List
Multi List - Example

You might also like