0% found this document useful (0 votes)
2 views22 pages

Day 04

Uploaded by

Utm Atm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views22 pages

Day 04

Uploaded by

Utm Atm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Singly Circular Linked List - Display

//1. create trav and start at head


//2. visit/print data of current node
//3. go on next node
//4. repeat step 2 and 3 till last node
Singly Circular Linked List - Add First

//1. create a newnode


//2. if list is empty
//a. add newnode into head and tail
//b. make list circular
//3. if list is not empty
//a. add first node into next of newnode
//b. add newnode into next of last node
//c. move head on newnode
Singly Circular Linked List - Add Last

//1. create a newnode


//2. if list is empty
//a. add newnode into head and tail
//b. make list circular
//3. if list is not empty
//a. add first node into next of newnode
//b. add newnode into next of last node
//c. move tail on newnode
Singly Circular Linked List - Add Position

//1. create newnode


//2. if list is empty
//a. add newnode into head & tail
//b. make list circular
3. if list is not empty
//a. traverse till pos-1
//b. add pos node into next of newnode
//c. add newnode into next of pos -1 node
Singly Circular Linked List - Delete first

//1. if list is empty


return;
//2. if list has single node
head = tail = null;
//3. if list has multiple nodes
//a. add second node into next of last node
//b. move head on second node
Singly Circular Linked List - Delete Last

//1. if list is empty


return;
//2. if list has single node
head = tail = null;
//3. if list has multiple node
//a. traverse till second last node
//b. add first node into next of second last node
//c. move tail on second last node
Singly Circular Linked List - Delete Position

//1. if list is empty


return;
//2. if list has single
head = tail = null;
//3. if list has multiple nodes
//a. traverse till pos - 1 node
//b. add pos + 1 node into next of pos - 1 node
Doubly Linear Linked List - Display

// forward traversal // reverse traversal


//1. start at head //1. start at tail
//2. print current node //2. print current node
//3. go on next node //3. go on prev node
//4. repeat step 2 and 3 till last node //4. repeat step 2 and 3 till first node
Doubly Linear Linked List - Add First

//1. create node


//2. if list is empty
// add newnode into head and tail
//3. if list is not empty
//a. add first node into next of newnode
//b. add newnode into prev of first node
//c. move head on newnode
Doubly Linear Linked List - Add Last

//1. create node


//2. if list is empty
// add newnode into head and tail
//3. if list is not empty
//a. add last node into prev of newnode
//b. add newnode into next of last node
//c. move tail on newnode
Doubly Linear Linked List - Delete First

//1. if list is empty


return;
//2. if list has single node
head = tail = null;
//3. if list has multiple node
//a. move head on second node
//b. make prev of second node equal to null
Doubly Linear Linked List - Delete Last

//1. if list is empty


return;
//2. if list has single node
head = tail = null;
//3. if list has multiple node
//a. move tail on second last node
//b. make next of second last node equal to null
Doubly Circular Linked List - Display

// forward traversal // reverse traversal


//1. start at head //1. start at tail
//2. print current node //2. print current node
//3. go on next node //3. go on prev node
//4. repeat step 2 and 3 till last node //4. repeat step 2 and 3 till first node
Doubly Circular Linked List - Add first

//a. create a newnode


//b. if list is empty
//1. add newnode into head
//2. make list circular
//c. if list is not empty
//1. add first node into next of newnode
//2. add last node into prev of newnode
//3. add newnode into next of last node
//4. add newnode into prev of first node
//5. move head on newnode
Doubly Circular Linked List - Add Last

//a. create a newnode


//b. if list is empty
//1. add newnode into head
//2. make list circular
//c. if list is not empty
//1. add first node into next of newnode
//2. add last node into prev of newnode
//3. add newnode into next of last node
//4. add newnode into prev of first node
Doubly Circular Linked List - Add position

//a. create a newnode


//b. if list is empty
//1. add newnode into head
//2. make list circular
//c. if list is not empty
// traverse till pos-1 node
//1. add pos node into next of newnode
//2. add pos-1 node into prev of newnode
//3. add newnode into next of pos-1 node
//4. add newnode into prev of pos node
Doubly Circular Linked List - Delete First

//1. if list is empty


return;
//2. if list has single node
head = null;
//3. if list has multiple node
//a. add laast node into prev of second node
//b. add second node into next of last node
//c. move head on second node
Doubly Circular Linked List - Delete Last

//1. if list is empty


return;
//2. if list has single node
head = null;
//3. if list has multiple node
//a. add first node into next of second last node
//b. add second last node into prev of first node
Doubly Circular Linked List - Delete Position

//1. if list is empty


return;
//2. if list has single node
head = null;
//3. if list has multiple nodes
//a. traverse till pos node
//b. add pos-1 node into prev of pos+1 node
//c. add pos+1 node into next of pos-1 node
Linked List Applications
- linked list is a dynamic data structure (grow or shrink at any time)
- due to this dynamic nature, linked list is used to implement other
data structures like:
1. stack
2. queue
3. hash tables
Deque
4. graph
(Double Ended Queue)

Stack Queue
LIFO FIFO

Input Restricted Deque


1. Add first 1. Add first
Delete first Delete last

Output Restricted Deque


2. Add last 2. Add last
Delete lats Delete first
Array Vs Linked List

Array Linked List


1. Array space in memory is 1. Linked list space in memory is
contiguous not contiguous

2. Array can not grow or shrink 2. Linked list can grow or shrink
at runtime at runtime

3. Random access of elements is 3. Random access of elements is


allowed not allowed(sequential)

4. Insert or Delete, needs shifting 4. Insert or Delete, do not need shifting


of array elements of nodes

5. Array needs less space 5. Linked lists need more space

You might also like