Skip to main content

double link list

/* double link list */
#include<iostream>
using namespace std;
class dnode
{
private:
dnode *prev;
int data;
dnode *next;
public:
void insert();
void add();
void search();
void update();
void delet();
void show();



};

dnode *head=NULL;
dnode *tail=NULL;
dnode *temp=NULL;
dnode *current=NULL;
int size=0;
int num,p;




int main()
{
dnode d1;
string x;
while(1)
{
cout<<"\n -------------------------------"<<endl;
cout<<"\n\n=> 1 to insert node"<<endl;
cout<<"\n=> 2 to Add node"<<endl;
cout<<"\n=> 3 to Search in Nodes"<<endl;
cout<<"\n=> 4 to update a value"<<endl;
cout<<"\n=> 5 to delete a node"<<endl;
cout<<"\n=> 6 to display"<<endl;
cout<<"\n=> 7 to exit: ";
cin>>x;
cout<<"\n -------------------------------"<<endl;

if(x=="1")
{
d1.insert();
}

else if(x=="2")
{
d1.add();
}
else if(x=="3")
{
d1.search();
}
else if(x=="4")
{
d1.update();
}

else if(x=="5")
{
d1.delet();
}
else if(x=="6")
{
d1.show();
}

else if(x=="7")
{
return 0;
}
else
{
cout<<"\nInvalid command\n"<<endl;
}


}





}


//Insertion function

void dnode::insert()
{
cout<<"_________________________________"<<endl;
cout<<"\nEnter number: ";
cin>>num;

temp=new dnode;
temp->prev=NULL;
temp->data=num;
temp->next=NULL;

if(head==NULL || size==0)
{
head=temp;
tail=temp;
current=temp;
}
else
{
tail->next=temp;
temp->prev=tail;
tail=temp;
current=temp;


}

size++;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<"\nNode inserted\n"<<endl;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;




}

//Insertion function



//add Function
void dnode::add()
{
if(size==0)
{
cout<<"\n_______________________________________________"<<endl;
cout<<"\nList is Empty Please First insert nodes"<<endl;
cout<<"\nTo Add B/W them\n"<<endl;
cout<<"_______________________________________________"<<endl;
}
else
{


cout<<"\nEnter position (0 to add in start)"<<endl;
cout<<"\nOR Enter any from 1 - "<<size<<": ";

cin>>p;

if(p<0 || p>size)
{
cout<<"\nInvalid Position\n"<<endl;

}
else
{
cout<<"\nEnter number: ";
cin>>num;

temp=new dnode;
temp->prev=NULL;
temp->data=num;
temp->next=NULL;

if(p==0)
{


temp->next=head;
head->prev=temp;
head=temp;
current=temp;

}

if(p>0 && p<size)
{

int mid=size/2;

if(p<=mid)
{
current=head;
for(int i=1;i<p;i++)
{
current=current->next;
}
temp->next=current->next;
temp->prev=current;
current->next->prev=temp;
current->next=temp;
current=temp;

}

if(p>mid)
{

current=tail;
for(int i=size;i>p;i--)
{
current=current->prev;
}

temp->next=current->next;
temp->prev=current;
current->next->prev=temp;
current->next=temp;
current=temp;

}



}

if(p==size)
{
tail->next=temp;
temp->prev=tail;
tail=temp;
current=temp;

}
size++;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<"\nNode Added\n"<<endl;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;

}

}


}

//add Function



//search Function

void dnode::search()
{
if(size==0)
{
cout<<"\n*************************"<<endl;
cout<<"\nList is Empty\n"<<endl;
cout<<"\n*************************"<<endl;
}
else
{
bool flag=false;
cout<<"\nEnter number to search in the List: ";
cin>>num;

current=head;
while(current!=NULL)
{
if(current->data==num)
{
flag=true;
break;
}

{
current=current->next;
}
}

if(flag==true)
{
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"<<endl;
cout<<"\n"<<current->data<<": Founded in the List\n"<<endl;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"<<endl;
}

if(flag==false)
{
cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"<<endl;
cout<<"\n"<<num<<": Not Founded in the List\n"<<endl;
cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"<<endl;

}

}




}
//search Function



//Updation Function
void dnode::update()
{
if(size==0)
{
cout<<"\n*************************"<<endl;
cout<<"\nList is Empty\n"<<endl;
cout<<"\n*************************"<<endl;
}
else
{
bool flag=false;
cout<<"\nEnter number to search in the List: ";
cin>>num;

current=head;
while(current!=NULL)
{
if(current->data==num)
{
flag=true;
break;
}

{
current=current->next;
}
}

if(flag==true)
{
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"<<endl;
cout<<"\n"<<current->data<<": Founded in the List\n"<<endl;
cout<<"\nEnter new number to update the existing: ";
cin>>num;
current->data=num;
cout<<"\n_________________________"<<endl;
cout<<"\nNode updated\n"<<endl;
cout<<"_________________________\n"<<endl;

cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"<<endl;
}

if(flag==false)
{
cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"<<endl;
cout<<"\n"<<num<<": Not Founded in the List\n"<<endl;
cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"<<endl;
}

}




}

//Updation Function




//Deletion function

void dnode::delet()
{

if(size==0)
{
cout<<"\n*************************"<<endl;
cout<<"\nList is Empty\n"<<endl;
cout<<"\n*************************"<<endl;
}
else
{
cout<<"\nEnter position of node from 1 - "<<size<<" to Delete: ";
cin>>p;

if(p<1 || p>size)
{
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<"\nInvalid Position\n"<<endl;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
}
else
{


if(p==1)
{
if(size==1)
{
current=head;
delete current;
head=NULL;
current=NULL;
temp=NULL;

}

else if(size>1)
{

current=head;
head=current->next;
delete current;
head->prev=NULL;
current=head;
}

}

if(p>1 && p<size)
{
int mid=size/2;

if(p<=mid)
{
current=head;
for(int i=1;i<p;i++)
{
current=current->next;
}

temp=current->prev;
temp->next=current->next;
current->next->prev=temp;
delete current;
current=temp;

}
if(p>mid)
{

current=tail;
for(int i=size; i>p;i--)
{
current=current->prev;
}

temp=current->prev;
temp->next=current->next;
current->next->prev=temp;
delete current;
current=temp;

}


}

if(p==size &&p>1)
{

current=tail;
tail=current->prev;
delete current;

tail->next=NULL;
current=temp;
}
size--;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;

cout<<"\nNode Deleted\n"<<endl;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;

}
}



}
//Deletion function


//Display Function
void dnode::show()
{
if(size==0)
{
cout<<"\n*************************"<<endl;

cout<<"\nList is Empty\n"<<endl;
cout<<"\n*************************"<<endl;
}
else
{

current=head;
cout<<"\n*****************************************************\n"<<endl;
cout<<"Total Node(s): "<<size<<"\n"<<endl;
while(current!=NULL)
{
cout<<current->data<<"  ";
current=current->next;
}

cout<<"\n*****************************************************\n"<<endl;

}


}

//Display Function#include<iostream>
using namespace std;
class dnode
{
private:
dnode *prev;
int data;
dnode *next;
public:
void insert();
void add();
void search();
void update();
void delet();
void show();



};

dnode *head=NULL;
dnode *tail=NULL;
dnode *temp=NULL;
dnode *current=NULL;
int size=0;
int num,p;




int main()
{
dnode d1;
string x;
while(1)
{
cout<<"\n -------------------------------"<<endl;
cout<<"\n\n=> 1 to insert node"<<endl;
cout<<"\n=> 2 to Add node"<<endl;
cout<<"\n=> 3 to Search in Nodes"<<endl;
cout<<"\n=> 4 to update a value"<<endl;
cout<<"\n=> 5 to delete a node"<<endl;
cout<<"\n=> 6 to display"<<endl;
cout<<"\n=> 7 to exit: ";
cin>>x;
cout<<"\n -------------------------------"<<endl;

if(x=="1")
{
d1.insert();
}

else if(x=="2")
{
d1.add();
}
else if(x=="3")
{
d1.search();
}
else if(x=="4")
{
d1.update();
}

else if(x=="5")
{
d1.delet();
}
else if(x=="6")
{
d1.show();
}

else if(x=="7")
{
return 0;
}
else
{
cout<<"\nInvalid command\n"<<endl;
}


}





}


//Insertion function

void dnode::insert()
{
cout<<"_________________________________"<<endl;
cout<<"\nEnter number: ";
cin>>num;

temp=new dnode;
temp->prev=NULL;
temp->data=num;
temp->next=NULL;

if(head==NULL || size==0)
{
head=temp;
tail=temp;
current=temp;
}
else
{
tail->next=temp;
temp->prev=tail;
tail=temp;
current=temp;


}

size++;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<"\nNode inserted\n"<<endl;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;




}

//Insertion function



//add Function
void dnode::add()
{
if(size==0)
{
cout<<"\n_______________________________________________"<<endl;
cout<<"\nList is Empty Please First insert nodes"<<endl;
cout<<"\nTo Add B/W them\n"<<endl;
cout<<"_______________________________________________"<<endl;
}
else
{


cout<<"\nEnter position (0 to add in start)"<<endl;
cout<<"\nOR Enter any from 1 - "<<size<<": ";

cin>>p;

if(p<0 || p>size)
{
cout<<"\nInvalid Position\n"<<endl;

}
else
{
cout<<"\nEnter number: ";
cin>>num;

temp=new dnode;
temp->prev=NULL;
temp->data=num;
temp->next=NULL;

if(p==0)
{


temp->next=head;
head->prev=temp;
head=temp;
current=temp;

}

if(p>0 && p<size)
{

int mid=size/2;

if(p<=mid)
{
current=head;
for(int i=1;i<p;i++)
{
current=current->next;
}
temp->next=current->next;
temp->prev=current;
current->next->prev=temp;
current->next=temp;
current=temp;

}

if(p>mid)
{

current=tail;
for(int i=size;i>p;i--)
{
current=current->prev;
}

temp->next=current->next;
temp->prev=current;
current->next->prev=temp;
current->next=temp;
current=temp;

}



}

if(p==size)
{
tail->next=temp;
temp->prev=tail;
tail=temp;
current=temp;

}
size++;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<"\nNode Added\n"<<endl;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;

}

}


}

//add Function



//search Function

void dnode::search()
{
if(size==0)
{
cout<<"\n*************************"<<endl;
cout<<"\nList is Empty\n"<<endl;
cout<<"\n*************************"<<endl;
}
else
{
bool flag=false;
cout<<"\nEnter number to search in the List: ";
cin>>num;

current=head;
while(current!=NULL)
{
if(current->data==num)
{
flag=true;
break;
}

{
current=current->next;
}
}

if(flag==true)
{
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"<<endl;
cout<<"\n"<<current->data<<": Founded in the List\n"<<endl;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"<<endl;
}

if(flag==false)
{
cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"<<endl;
cout<<"\n"<<num<<": Not Founded in the List\n"<<endl;
cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"<<endl;

}

}




}
//search Function



//Updation Function
void dnode::update()
{
if(size==0)
{
cout<<"\n*************************"<<endl;
cout<<"\nList is Empty\n"<<endl;
cout<<"\n*************************"<<endl;
}
else
{
bool flag=false;
cout<<"\nEnter number to search in the List: ";
cin>>num;

current=head;
while(current!=NULL)
{
if(current->data==num)
{
flag=true;
break;
}

{
current=current->next;
}
}

if(flag==true)
{
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"<<endl;
cout<<"\n"<<current->data<<": Founded in the List\n"<<endl;
cout<<"\nEnter new number to update the existing: ";
cin>>num;
current->data=num;
cout<<"\n_________________________"<<endl;
cout<<"\nNode updated\n"<<endl;
cout<<"_________________________\n"<<endl;

cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"<<endl;
}

if(flag==false)
{
cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"<<endl;
cout<<"\n"<<num<<": Not Founded in the List\n"<<endl;
cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"<<endl;
}

}




}

//Updation Function




//Deletion function

void dnode::delet()
{

if(size==0)
{
cout<<"\n*************************"<<endl;
cout<<"\nList is Empty\n"<<endl;
cout<<"\n*************************"<<endl;
}
else
{
cout<<"\nEnter position of node from 1 - "<<size<<" to Delete: ";
cin>>p;

if(p<1 || p>size)
{
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<"\nInvalid Position\n"<<endl;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
}
else
{


if(p==1)
{
if(size==1)
{
current=head;
delete current;
head=NULL;
current=NULL;
temp=NULL;

}

else if(size>1)
{

current=head;
head=current->next;
delete current;
head->prev=NULL;
current=head;
}

}

if(p>1 && p<size)
{
int mid=size/2;

if(p<=mid)
{
current=head;
for(int i=1;i<p;i++)
{
current=current->next;
}

temp=current->prev;
temp->next=current->next;
current->next->prev=temp;
delete current;
current=temp;

}
if(p>mid)
{

current=tail;
for(int i=size; i>p;i--)
{
current=current->prev;
}

temp=current->prev;
temp->next=current->next;
current->next->prev=temp;
delete current;
current=temp;

}


}

if(p==size &&p>1)
{

current=tail;
tail=current->prev;
delete current;

tail->next=NULL;
current=temp;
}
size--;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;

cout<<"\nNode Deleted\n"<<endl;
cout<<"\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;

}
}



}
//Deletion function


//Display Function
void dnode::show()
{
if(size==0)
{
cout<<"\n*************************"<<endl;

cout<<"\nList is Empty\n"<<endl;
cout<<"\n*************************"<<endl;
}
else
{

current=head;
cout<<"\n*****************************************************\n"<<endl;
cout<<"Total Node(s): "<<size<<"\n"<<endl;
while(current!=NULL)
{
cout<<current->data<<"  ";
current=current->next;
}

cout<<"\n*****************************************************\n"<<endl;

}


}

//Display Function

Comments

Popular posts from this blog

C++ Projects (MAKING DMC )

c++ project of dmc #include<iostream> #include<fstream> #include<iomanip> #include<conio.h> #include<windows.h> using namespace std; class student { protected : char  name[50]; int roll; char board[50]; }; class dmc:public student { protected : float per; int phy; int maths; int cs; int english; public : void getdata() { cout<<"ENTER NAME : "; cin>>name; cout<<"ENTER ROLL : "; cin>>roll; cout<<"PHYSIC MARK : "<<endl; cin>>phy; cout<<"MATHS MARKS :"<<endl; cin>>maths; cout<<"ENTER CS MARKS :"<<endl; cin>>cs; cout<<"ENTER ENGLISH MARKS : "<<endl; cin>>english;    } float calculate() { per=(((phy+maths+cs+english)*(100))/400); return per; } double add() { double total...

C++ project of school mangment system

            C++ SIMPLE PROJECT FOR STORYING RECORDS OF STUDENTS    POST COMMENT FOR ANY ERROR OR IF YOU HAVE ANY PROBLEM WITH THE                                                           CODE  #include<iostream>  #include<windows.h> using namespace std; int main() { string name[3]; int id[3] ; int count=0; int z; int y; int ch; int k; int roll; int c; int dd; char yy; cout<<"*************************WELLCOME TO DATABASE         SYSTM*********************"<<endl; while(1) { cout<<"\t\tpress 1 for entry "<<endl; cout<<"\t\tpress 2 for full data display "<<endl;          cout<<"\t\tpress 3 changing :  "<<endl;           c...