Full functional circular linked list in C++

A full functional circular linked list is that in which maximum function are defined.Like how to
Create a list.
Display a list.
Create node at start of list.
Delete node at start of list.
Create node at end of list.
Delete node at the start of list.
Insertion and deletion in middle of list.
Counting number of nodes.
Calculating sum of all nodes data.
Breaking a list into two parts.
Joining two lists together.


There are many other functions that helps user to manage linked list in a better way.In below program many functions are written to create easiness for programmer.However in some functions working may not be implemented.This is because these functions are very simple and programmer can write that methods easily by analyzing other methods.So just copy the program and show your programming experience to the world.


#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;

struct node
{
int data;
node *link;
}*head=NULL;


void create()
{
node *new1=NULL;
node *end=new1;
cout<<"Enter -5 to terminate link list:"<<endl;
while(1)
{
 int info;
cout<<"Enter data: ";
cin>>info;
if(info==-5)
break;
new1=new node;
new1->data=info;
if(head==NULL)
head=new1;
else
end->link=new1;;
end=new1;
end->link=head;


 } 
}

void display()
{
node *p=head;
cout<<"\n\nYour output is:";
while(p->link!=head)
{
cout<<"   "<<p->data;
p=p->link; 
 }
cout<<"  "<<p->data;  
}



void single_node()
{
cout<<"\n\nThis function is not available"; 
}





void delete_first()
{
cout<<"\n\nThis function is not available"; 
}


void delete_last()
{
cout<<"\n\nThis function is not available"; 
}



void  create_first()
{
cout<<"\n\nThis function is not available"; 
}


void create_last()
{
cout<<"\n\nThis function is not available"; 
}


void count_nodes()
{
cout<<"\n\nThis function is not available"; 
}


void sum()
{
cout<<"\n\nThis function is not available"; 
}


void specific_node()
{
cout<<"\n\nThis function is not available"; 
}


void create_before()
{
cout<<"\n\nThis function is not available"; 
}

void delete_before()
{
cout<<"\n\nThis function is not available"; 
}

main()
{
int choice; 
cout<<"\t***Circular link list***"<<endl;
do
{
system("color F"); 
cout<<"Enter 1 to create single node:"<<endl;
cout<<"Enter 2 to create multiple nodes:"<<endl;
cout<<"Enter 3 to delete node from first:"<<endl;
cout<<"Enter 4 to delete node from last:"<<endl;
cout<<"Enter 5 to create node at first:"<<endl;
cout<<"Enter 6 to create node at last:"<<endl;
cout<<"Enter 7 to count number of nodes in link list:"<<endl;
cout<<"Enter 8 to sum all data in nodes:"<<endl;
cout<<"Enter 9 to select and display specific node:"<<endl;
cout<<"Enter 10 to create node before any node:"<<endl;
cout<<"Enter 11 to delete node before any node:"<<endl;
cout<<"Enter 12 to display curent link list:"<<endl;
cout<<"Enter 13 to exit"<<endl;
cin>>choice;

switch(choice)
{
case 1:
single_node(); //creates single node
break;

case 2:
create(); //creates multiple nodes
break;

case 3:
delete_first(); //delete node from first
break;

case 4:
delete_last(); //delete node from last
break;

case 5:
create_first();  //create node at first
break;

case 6:
create_last();  //create node at last
break;

case 7:
count_nodes(); //count number of nodes
break;

case 8:
sum(); //sum all nodes data
break;

case 9:
specific_node(); //display specific node data
break;

case 10:
create_before(); //create node before any node
break;

case 11:
delete_before(); //delete node before any node 
break;

case 12:
display(); //display entire node
break;

case 13://exit path
cout<<"\nPRogram ended";
break;

default:
cout<<"Wrong input"<<endl;
}}while(choice!=13) ;
getch();
 
}

Reactions

Post a Comment

0 Comments