team 10

19
DATA STRUCTURES CIRCULAR LINKED LIST ASSIGNMENT PRESENTAION - I

Upload: sathasivam-r

Post on 02-Aug-2015

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Team 10

DATA STRUCTURES

CIRCULAR LINKED LIST

ASSIGNMENT PRESENTAION - I

Page 2: Team 10

TOPICSWhat is linked list?

Types of Linked List

Circular Linked List

Introduction

Operations on a Circular Linked List

Advantages and Disadvantages of Circular Linked List

Applications

Page 3: Team 10

What is linked list? A Linked list is a data structure consisting of a

group of nodes which together represent a sequence.

Each node is composed of a data and a link to the next node in the sequence

The nodes are used to store data.

Page 4: Team 10

Types of Linked List

Linear singly linked list

Circular link list

Doubly linked list (or) two way linked list

Circular doubly linked list.

Page 5: Team 10

Linked list creation

struct node { int data;

struct node * next; };struct node *new,*head,*ptr;

Page 6: Team 10

Circular Linked ListIn the circular list, the pointer of the last

node points not NULL but points to the

first node.

The tail element's next pointer points to

the head element.

If there’s only one element, the element's

previous and next pointers point to itself

and it is both the head and tail of the list.

Page 7: Team 10

Circular Linked List Without Header

Circular Linked List With Header

Page 8: Team 10

Operations on a Circular Linked List:

Insertion

Deletion

1.Insertion :

We can insert a new node in 3 different places.

1. Insert to head of a Circular Linked List

2. Insert to end of a Circular Linked List

3. Insert to middle of a Circular Linked List

Page 9: Team 10

Creation of a node

head

new = (struct node * ) malloc ( size of (struct node ));

new data = 1;

head = new;

new next = head;

1

Page 10: Team 10

1.Insert to head of a Circular Linked List

head

ptr

new = (struct node * ) malloc ( size of (struct node ));

new data = 0;

while( ptr next ! = head )

ptr = ptr next;

new next = head;

head = new;

ptr next = new;

0

1 2 3

Page 11: Team 10

2.Insert to end of a Circular Linked List

head

ptr

new = (struct node * ) malloc ( size of (struct node ));

new data = 3;

ptr = head ;

while ( ptr next ! = head )

ptr = ptr next;

ptr next = new;

new next = head;

0 1

3

Page 12: Team 10

3.Insert to middle of a Circular Linked List head

ptr

new = (struct node * ) malloc ( size of (struct node ));

new data = 2;

pos = 3;

ptr = head;

while( ptr < pos - 1 )

ptr = ptr next;

new next = ptr next;

ptr next = new;

0 1 3

2

Page 13: Team 10

Deletion of nodes

We can delete a node form 3 different places.

1.Delete the head node from a Circular

Linked List

2.Delete the end node from a Circular Linked

List

3.Delete a middle node from a Circular

Linked List

Page 14: Team 10

1.Delete the first node from a Circular Linked List

head

ptr

ptr = head;

while ( ptr next ! = head )

ptr = ptr next;

ptr next = head next;

free(head);

0 1 2

Page 15: Team 10

2.Delete the end node from a Circular Linked List head

temp ptr

ptr = head , temp = head;

while ( ptr next ! = head )

{

temp = ptr;

ptr = ptr next;

}

temp next = head;

free(ptr);

0 1 2

Page 16: Team 10

3.Delete a middle node from a Circular Linked List

head

data = 1;

ptr = head , temp = head;

while( ptr -> data ! = data )

{

temp = ptr;

ptr = ptr next;

}

temp next = ptr next;

free( ptr );

0 1 2

Page 17: Team 10

Advantages and Disadvantages of Circular Linked List Advantages:

1. If we are at a node, then we can go to any node. But in

linear linked list it is not possible to go to previous node.

2. It saves time when we have to go to the first node from

the last node.

Disadvantages:

1. It is not easy to reverse the linked list.

2. If we at a node and go back to the previous node, then

we can not do it in single step.

Page 18: Team 10

Applications of Circular Linked List

1. Round Robin Time Sharing jobs of Operating

System, ie simple multi tasking by PC . For this

application, there should be no NULL pointers

unless there is absolutely no one requesting

CPU time.

2. Chit Funds use the concept of circular first

come first serve linked list 

Page 19: Team 10

THANK YOU...