Professional Documents
Culture Documents
struct node
int data;
node *next;
};
node *tail;
class circular_llist
public:
create_node(int value)
temp->data = value;
if (tail == NULL)
tail = temp;
temp->next = tail;
else
temp->next = tail->next;
tail->next = temp;
tail = temp;
if (tail == NULL)
return;
temp->data = value;
temp->next = tail->next;
tail->next=temp;
}
/*
*/
if (tail == NULL)
return;
node *s;
s = tail->next;
s = s->next;
temp->next = s->next;
temp->data = value;
s->next = temp;
if (s == tail)
tail=temp;
/*
* Deletion of element from the list
*/
s = tail->next;
{ temp = tail;
tail = NULL;
return;
temp = s;
tail->next = s->next;
delete temp;
return;
if (s->next->data == value)
temp = s->next;
s->next = temp->next;
delete temp;
cout<<"Element "<<value;
return;
}
s = s->next;
if (s->next->data == value)
temp = s->next;
s->next = tail->next;
tail = s;
return;
/*
*/
{
node *s;
int counter = 0;
s = tail->next;
while (s != tail)
counter++;
if (s->data == value)
cout<<"Element "<<value;
return;
s = s->next;
}
if (s->data == value)
counter++;
cout<<"Element "<<value;
return;
/*
*/
void display_list()
{
node *s;
if (tail == NULL)
return;
s = tail->next;
while (s != tail)
cout<<s->data<<"->";
s = s->next;
cout<<s->data<<endl;
}
/*
*/
void update()
if (tail == NULL)
return;
cin>>pos;
cout<<"Enter the new value: ";
cin>>value;
s = tail->next;
if (s == tail)
cout<<endl;
return;
s = s->next;
}
s->data = value;
cout<<"Node Updated"<<endl;
/*
*/
void sort()
int temp;
if (tail == NULL)
return;
}
s = tail->next;
while (s != tail)
ptr = s->next;
if (ptr != tail->next)
temp = s->data;
s->data = ptr->data;
ptr->data = temp;
}
else
break;
ptr = ptr->next;
s = s->next;
circular_llist()
tail = NULL;
}
};
int main()
circular_llist cl;
int b=1;
while (b)
cout<<endl<<"---------------------------"<<endl;
cout<<endl<<"---------------------------"<<endl;
cout<<"1.Create Node"<<endl;
cout<<"2.Add at beginning"<<endl;
cout<<"3.Add after"<<endl;
cout<<"4.Delete"<<endl;
cout<<"5.Search"<<endl;
cout<<"6.Display"<<endl;
cout<<"7.Update"<<endl;
cout<<"8.Sort"<<endl;
cout<<"9.Quit"<<endl;
cin>>choice;
switch(choice)
case 1:
cin>>element;
cl.create_node(element);
cout<<endl;
break;
case 2:
cin>>element;
cl.add_begin(element);
cout<<endl;
break;
case 3:
cin>>element;
cin>>position;
cl.add_position(element, position);
cout<<endl;
break;
case 4:
if (tail == NULL)
break;
cin>>element;
cl.delete_element(element);
cout<<endl;
break;
case 5:
if (tail == NULL)
break;
cin>>element;
cl.search_element(element);
cout<<endl;
break;
case 6:
cl.display_list();
break;
case 7:
cl.update();
break;
case 8:
cl.sort();
break;
case 9:
exit(1);
break;
default:
cout<<"Wrong choice"<<endl;
return 0;