Showing posts with label link list. Show all posts
Showing posts with label link list. Show all posts

Saturday, October 25, 2014

Double Link-List in C++

#include<iostream.h>
#include<conio.h>
class node
{
public:
int value,size;
node *nextnode,*headnode,*prenode;
node *lastnode,*currentnode;
public:
node();
void add(int);
int get()
{
return value;
}
void set(int value)
{
this->value=value;
}
void setnext(node *nextnode)
{
this->nextnode=nextnode;
}
node *getnext()
{ return nextnode;}
void setprev(node* prenode)
{this->prenode=prenode;}
node *getprev()
{ return prenode;}
void  display()
{ cout<<"Adress of headnode      "<<headnode<<"       Headnode hold: "<<headnode->getnext()<<endl;
for(node *a=headnode->getnext();a->getnext()!=NULL;a=a->getnext())
{

cout<<"\nAddress of  node:       "<<a;
cout<<"\nAdress of next node:    "<<a->getnext()<<"    Adress of Preves node: "<<a->getprev()<<endl;
cout<<"value of node:  "<<a->value<<endl;

}
}
};
node::node()
{
headnode=new node();
headnode->setnext(NULL);
currentnode=NULL;
size=0;
}
void node::add(int n)
{
node *newnode=new node();
newnode->set(n);
if(currentnode!=NULL)
{
nextnode->setnext(currentnode->getnext());
newnode->setprev(currentnode);
currentnode->setnext(newnode);
lastnode=currentnode;
currentnode=newnode;
}
else
{
newnode->setnext(NULL);
newnode->setprev(headnode);
headnode->setnext(newnode);
lastnode=headnode;
currentnode=newnode;

}
size++;
}
void main()
{
clrscr();
node obj,bol;

obj.add(10);
obj.add(20);
obj.add(30);
obj.add(40);
obj.add(50);

obj.display();

getch();
}


Deletion of Any node in Circular link-List

#include<iostream.h>
#include<conio.h>
class node{
private:
int value,size;
node *last,*first,*nextnode;
public:
node()                     //constructor
{value=size=0; last=first=nextnode=NULL;}
int get()
{ return value;  }
void set(int value)
{ this->value=value; }
node *getnext()
{ return nextnode; }
void setnext(node *nextnode)
{ this->nextnode=nextnode; }
void add(int n)
{
 node *newnode=new node();
 newnode->set(n);
 if(first==NULL && last==NULL)
 {
  newnode->setnext(NULL);
  first=newnode;
  last=newnode;
 }
  else
 {
 last->setnext(newnode);
 newnode->setnext(first);
 last=newnode;
 }
 size++;
}
void display()
{
cout<<"\nAdress of first node: "<<first<<"  Adress first node holding: "<<first->getnext()<<endl;
cout<<"Value of First node:    "<<first->get()<<endl;
for(node *a=first->getnext();a->getnext()!=first->getnext();a=a->getnext())
 {
 cout<<"\nAdres of node:  "<<a<<"    Adress that hold: "<<a->getnext()<<endl;
 cout<<"Value of node:  "<<a->get()<<endl;
 }
}
///// find functions :)
node *find(int n)
{
for(node *a=first->getnext();a!=first;a=a->getnext())
 {
 if(a->get()==n)
 return a;
 }
}
node *find1(node *n)
{
for(node *a=first->getnext();a->getnext()!=n->getnext();a=a->getnext())
 {
 if(a->getnext()==n)
 return a;
 }
}
///// Remove Function
void remove(int n)
{
node *p1=NULL;
 if(first==NULL && last==NULL)
 {  cout<<" \n List is Empty "; return;}
 else if(first==last && n==first->get())
 {  delete first,last; first=last=NULL; cout<<"\nvalues delete";return; }
else
 {
  node *p=find(n);

  if(p==first)
   { p1=last;
    p1->setnext(first->getnext());
    first=first->getnext();
    delete p;
   }
  else if(p==last)
     { p1=find1(p);
       p1->setnext(p->getnext());
       last=p1;
       delete p;
     }
   else
   {
     p1=find1(p);
     p1->setnext(p->getnext());
      delete p;
   }
 }
}
};
 void main()
 {
 clrscr();
 int v=0;
 node obj;
 obj.add(11);
 obj.add(12);
 obj.add(13);
 obj.add(14);
 obj.add(15);
 obj.add(16);
obj.display();
while(getch()==13)
 {
 cout<<"\n\nEnter the value of node you want to delete: ";
 cin>>v;
 clrscr();
 obj.remove(v);
 obj.display();
 cout<<"\n\n\n\n\t Delete other  ::Enter    ||   Exit::Any Key ";

 }
}

Friday, October 24, 2014

Circular Link-List in C++

#include<iostream.h>
#include<conio.h>
class node{
private:
int value,size;
node *last,*first,*nextnode;
public:
node()                     //constructor
{ last=first=NULL; }
int get()
{ return value;  }
void set(int value)
{ this->value=value; }
node *getnext()
{ return nextnode; }
void setnext(node *nextnode)
{ this->nextnode=nextnode; }
void add(int n)
{
 node *newnode=new node();
 newnode->set(n);
 if(first==NULL && last==NULL)
 {
  newnode->setnext(NULL);
  first=newnode;
  last=newnode;
 }
  else
 {
 last->setnext(newnode);
 newnode->setnext(first);
 last=newnode;
 }
 size++;
}
void display()
{
cout<<"Adress of first node: "<<first<<"  Adress first node holding: "<<first->getnext()<<endl;
for(node *a=first->getnext();a->getnext()!=first->getnext();a=a->getnext()){
cout<<"Adres of node: "<<a<<"    Adress that hold: "<<a->getnext()<<endl;
cout<<"Value of node: "<<a->get()<<endl<<endl;
}
}
};
 void main()
 {
 clrscr();
 node obj;
 obj.add(22);
 obj.add(33);
 obj.add(44);
 obj.add(55);
obj.display();
getch();
  }

Sunday, October 19, 2014

Concatenate or Merge two Linklists in C++

#include<iostream.h>
#include<conio.h>
class node
{
public:
int value,size;
node *nextnode,*headnode;
node *lastnode,*currentnode;
public:
node();
void add(int);
int get()
{
return value;
}
void set(int value)
{
this->value=value;
}
void setnext(node *nextnode)
{
this->nextnode=nextnode;
}
node *getnext()
{
return nextnode;
}

void  display()
{ cout<<"headnode hold: "<<headnode->getnext()<<endl;
for(node *a=headnode->getnext();a->getnext()!=NULL;a=a->getnext())
{

cout<<"Adress of  node:  "<<a<<"      Adress holdin /next node:  "<<a->getnext()<<endl;
cout<<"value of node:  "<<a->value<<endl<<endl;

}
}
friend void  conc( node c,node b)
{
c.currentnode->setnext(b.headnode->getnext());
delete b.headnode;
}
};
node::node()
{
headnode=new node();
headnode->setnext(NULL);
currentnode=NULL;
size=0;
}
void node::add(int n)
{
node *newnode=new node();
newnode->set(n);
if(currentnode!=NULL)
{
nextnode->setnext(currentnode->getnext());
currentnode->setnext(newnode);
lastnode=currentnode;
currentnode=newnode;
}
else
{
newnode->setnext(NULL);
headnode->setnext(newnode);
lastnode=headnode;
currentnode=newnode;

}
size++;
}
void main()
{
clrscr();
node obj,bol;
obj.add(11);
obj.add(20);
obj.add(30);
obj.add(40);
obj.display();
cout<<"Press any key to see 2nd link list: ";
getch();
clrscr();
cout<<endl<<"XXXXXXXXXXXXXXXXX"<<endl;
bol.add(25);
bol.add(23);
bol.add(22);
bol.display();
cout<<"Press any key to see 1st link list after concatination or merging ";
getch();
clrscr();
conc(obj,bol);
obj.display();
getch();
}

Sunday, October 12, 2014

Insertion at any point in LINK-LIST

#include<iostream.h>
#include<conio.h>
class node
{
private:
int value,size;
node *nextnode,*headnode;
node *lastnode,*currentnode;
public:
node();
void add(int);
int get()
{
return value;
}
void set(int value)
{
this->value=value;
}
void setnext(node *nextnode)
{
this->nextnode=nextnode;
}
node *getnext()
{
return nextnode;
}
void inline display()
{
for(node *a=headnode->getnext();a->getnext()!=NULL;a=a->getnext())
{

cout<<"address of  node  "<<a<<"       "<<a->getnext()<<endl;
cout<<a->value<<endl;

}
}
void find(int z)
{
int x;
cout<<endl<<"enter value";
cin>>x;
for(node *a=headnode->getnext();a->getnext()!=NULL;a=a->getnext())
if(a->get()==z)
currentnode=a;
node *newnode=new node();
newnode->set(x);
newnode->setnext(currentnode->getnext());
currentnode->setnext(newnode);
   }
};
node::node()
{
headnode=new node();
headnode->setnext(NULL);
currentnode=NULL;
size=0;
}
void node::add(int n)
{
node *newnode=new node();
newnode->set(n);
if(currentnode!=NULL)
{
nextnode->setnext(currentnode->getnext());
currentnode->setnext(newnode);
lastnode=currentnode;
currentnode=newnode;
}
else
{
newnode->setnext(NULL);
headnode->setnext(newnode);
lastnode=headnode;
currentnode=newnode;

}
size++;
}
void main()
{
clrscr();
int q;
node obj;
obj.add(10);
obj.add(20);
obj.add(30);

obj.add(40);
obj.display();
cout<<endl<<"Enetr a value for search: ";
cin>>q;
obj.find(q);
obj.display();
getch();
}

Tuesday, October 7, 2014

How to create a single linklist in C++

#include<iostream.h>
#include<conio.h>
class node{
private:
int value,size;
node *newnode,*currentnode,*prevnode,*headnode,*lastnode,*nextnode;
public:
node();
void add(int);
int get()
{
 return value;
}
void set(int value)
{
this->value=value;
}
node *getnext()
{
return nextnode;
}
void setnext(node *nextnode)
{
this->nextnode=nextnode;
}
node *getprev()
{
return prevnode;
}
void setprev(node *prevnode)
{
this->prevnode=prevnode;
}
};
node::node()
{
headnode=new node();
headnode->setnext(NULL);
currentnode=NULL;
size=0;
}
void node::add(int n)
{
node *newnode=new node();
newnode->set(n);
if(currentnode!=NULL)
{
newnode->setnext(currentnode->getnext());
currentnode->setnext(newnode);
lastnode=currentnode;
currentnode=newnode;
}
else
{
newnode->setnext(NULL);
headnode->setnext(newnode);
lastnode=headnode;
currentnode=newnode;
}size++;
}

void main()
{
node obj;
obj.add(10);
obj.add(20);
getch();
}


Saturday, September 20, 2014

Data Structure Programs

Read Also:  


"All Data Structure Programs up-till now"

To get code Click on that program heading :) ☺ ☻ 

 ALL Type Of Sorting Click here :: most important :: 

-------------------

`Queues 

----------------

`Single Link-List:

*  How to create single Link-list in C++

*  Insertion at any point in link-list in C++

*  Concatenate or Merge two Link-lists in C++

Deletion At any point in Circular Link List in C++
------------------------------------

`Double Link-list:

=================

Stacks Data Structure:


Decimal to binary conversion using stack in c++
============ 

How to add two matrix size is define by use






Program to print counting 10 to 1 using Recursion

--------------------------------------------------