Archive for the ‘DOUBLE_LINKED_LIST’ Category

DLL_DELETION_ANYWHERE

March 27, 2008

DOUBLE LINKED LIST DELETION AT ANY WHERE


HOME

/*.PROGRAM
TO IMPLEMENT DELETION ON

 DOUBLE
LINKED LIST USING SELFREFERENTIAL CLASSES.*/


#include<iostream.h>
int 
count=0;

class
dll   //CLASS
DECLARATION

{
private:
  
char data[11];

  
dll *left,*right;//DATA
MEMBERS

public:
  
 void inser_end( char[] );

  
 void del_any();

  
 void show();

}
*head;

//FUNCTION
FOR INSERTING NODE AT THE END

void
dll::inser_end(char s[])

{
  
 dll *n,*temp;

  
 n=new(dll);

  
 for(int i=0;s[i]!=”;i++)

  
 n->data[i]=s[i];

  
 n->data[i]=”;

  
 n->left=NULL;

  
 n->right=NULL;

  
 if(head==NULL)

  
     head=n;

  
 else

  
 {

  
 temp=head;

  
 while(temp->right!=NULL)

  
 {

  
 temp=temp->right;

  
 }

  
 temp->right=n;

  
 n->left=temp;

  
 }

}

  
     

//FUNCTION
FOR DISPLAY OUTPUT

void
dll::show()

{
   
count=0;

  
 dll *temp;

  
 if(head==NULL)

cout<<“NO
NODES IN THE LIST  “;

  
 else

  
 {

  
 temp=head;

  
 while(temp!=NULL)

  
 {

  
 count++;

  
 cout<<temp->data<<endl;

  
 temp=temp->right;

  
 }

  
 }

cout<<“THE
NO OF NODES ->”<<count<<endl;

}

//FUNCTION
FOR DELETING NODE AT ANY POSITION

void
dll::del_any()

{
  
 int pos;

  
 dll *temp,*old,*t;

cout<<“ENTER
THE POSITION OF DELETION”;

  
 cin>>pos;

  
 old=temp=head;

  
 if(pos==1)

  
     

  
 {

  
 temp=temp->right;

  
 t=temp;

  
 head=t;

  
 delete t;

  
 }

  
 

else
{
  
 

  
 for(int i=1;i<pos;i++)

  
 {

  
     old=temp;

  
     temp=temp->right;

  
 }

  
 if(pos==count)

  
 {

  
     temp->left=NULL;

  
     old->right=NULL;

  
     delete temp;

  
 }

  
 else

  
 {

  
 old->right=temp->right;

  
 temp->right->left=old;

   
delete temp;

  
 }

}
}

void 
main()//MAIN()
FUNCTION STARTS

{
  
 char x[22];

  
 int p;

  
 head=NULL;

  
 dll d;//OBJECT CREATION

cout<<“ENTER
THE NO OF STRINGS

     
TO BE INSERTED INTO THE LIST”;

  
 cin>>p;

  
 

cout<<“ENTER
THE “<<p<<”  STRINGS”;

  
 for(int i=0;i<p;i++)

  
 {

  
 cin>>x;

  
 d.inser_end(x);

  
 }

cout<<“AFTER
INSERTING AT

       
THE END THE LIST IS\n”;

  
 d.show();

  
 d.del_any();

cout<<“AFTER
DELETION THE

      
NODES IN THE  LIST ARE\n”;

  
 d.show();

}//END OF MAIN()

//PROGRAM
ENDS

/*
OUTPUT:
 
ENTER
THE NO OF STRINGS

 
TO BE INSERTED INTO THE LIST  4

ENTER
THE 4  STRINGS

BHANU
SURENDRA
SRI
SUKE
AFTER
INSERTING AT

     
THE END THE LIST IS

BHANU
SURENDRA
SRI
SUKE
THE
NO OF NODES ->4

ENTER
THE POSITION OF DELETION4

AFTER
DELETION THE

     
NODES IN THE  LIST ARE

BHANU
SURENDRA
SRI
THE
NO OF NODES ->3

Press
any key to continue

*/

HOME

Advertisements

DLL_INSERTION_AT_ANYWHERE

March 27, 2008

DOUBLE LINKEDLIST INSERTION AT ANY POSITION

HOME
/*..PROGRAM
TO IMPLEMENT INSERSION AT ANYWHERE

 ON
DOUBLE LINKED LIST USING SELFREFERENTIAL CLASSES..*/


#include<iostream.h>
int 
count=0;

class
dll   //CLASS
DECLARATION

{
private:
  
char data[11];

  
dll *left,*right;//DATA
MEMBERS

public:
         //MEMBER FUNCTIONS
  
 void inser_end( char[] );

  
 void inser_beg(char[] );

       
void inser_any(char[]);

  
 void show();

}
*head;

//FUNCTION
FOR INSERTING NODE AT THE END

void
dll::inser_end(char s[])

{
  
 dll *n,*temp;

  
 n=new(dll);

  
 for(int i=0;s[i]!=”;i++)

  
 n->data[i]=s[i];

  
 n->data[i]=”;

  
 n->left=NULL;

  
 n->right=NULL;

  
 if(head==NULL)

  
     head=n;

  
 else

  
 {

  
 temp=head;

  
 while(temp->right!=NULL)

  
 {

  
 temp=temp->right;

  
 }

  
 temp->right=n;

  
 n->left=temp;

  
 }

}

/*FUNCTION
FOR INSERTING NODE
  AT THE BEGGNING*/

void
dll::inser_beg(char s1[ ])

{
  
 dll *n,*temp;

  
 n=new(dll);

  
 for(int i=0;s1[i]!=”;i++)

  
 n->data[i]=s1[i];

  
 n->data[i]=”;

  
 n->right=NULL;

  
 n->left=NULL;

  
 if(head==NULL)

  
     head=n;

  
 else

  
 {

  
 temp=head;

  
 n->right=temp;

  
 temp->left=n;

  
 head=n;

  
 }

}
  
 

//FUNCTION
FOR INSERTING NODE AT ANY POSITION

void
dll::inser_any(char s[ ])

{
  
 int pos;

  
 dll *n,*temp,*old;

  
 n=new(dll);

  
 for(int i=0;s[i]!=”;i++)

  
 n->data[i]=s[i];

  
 n->data[i]=s[i];

  
 n->right=NULL;

  
 n->left=NULL;

  
 cout<<“ENTER THE POSITON

          &nb

sp;     
OF INSERTION”;
  
 cin>>pos;

  
 if(pos>count+1)

  
 cout<<“INSUFFICIENT NODES TO

          &nb

sp;  
INSERT AT “<<pos<<” POSITION\n”;
  
 else

  
 {

   
temp=old=head;

  
 if(pos==1)

  
   inser_beg(s);

  
 else

  
 if(pos==count+1)

  
     inser_end(s);

  
 else

  
 {

  
 for(i=1;i<pos;i++)

  
 {  

  
     old=temp;

  
    temp=temp->right;

  
 }

  
 old->right=n;

  
 temp->left=n;

  
 n->right=temp;

  
 n->left=old;

  
 }

  
 }

}

  
     

//FUNCTION
FOR DISPLAY OUTPUT

void
dll::show()

{
   
count=0;

  
 dll *temp;

  
 if(head==NULL)

  
 cout<<“NO NODES IN THE LIST  “;

  
 else

  
 {

  
 temp=head;

  
 while(temp!=NULL)

  
 {

  
 count++;

  
 cout<<temp->data<<endl;

  
 temp=temp->right;

  
 }

  
 }

cout<<“THE
NO OF NODES ->”<<count<<endl;

}
void 
main()//MAIN()
FUNCTION STARTS

{
  
 char x[22];

  
 head=NULL;

  
 dll d;//OBJECT CREATION

cout<<“THE
STRINGS IN THE LIST ARE\n”;

  
 d.inser_end(“Bhanu”);

  
 d.inser_end(“Surendra”);

  
 d.inser_end(“Durga”);

  
 d.inser_end(“Kartheek”);

  
 d.show();

  
 

cout<<“ENTER
THE STRING TO BE

     
INSERTED AT SPECIED POSITION\n”;

  
 cin>>x;

  
 d.inser_any(x);

  
 d.show();

  
 

}//END OF MAIN()

//PROGRAM
ENDS

/*
OUTPUT:

THE
STRINGS IN THE LIST ARE

Bhanu
Surendra
Durga
Kartheek
THE
NO OF NODES ->4

ENTER
THE STRING TO BE INSERTED

           

  
AT SPECIED POSITION

PHANI
ENTER
THE POSITON OF INSERTION2

Bhanu
PHANI
Surendra
Durga
Kartheek
THE
NO OF NODES ->5

Press
any key to continue

*/

HOME

DLL_INSERTION_AT_REAREND

March 27, 2008

DOUBLE LINKED LIST INSERSION AT END

HOME

/*.PROGRAM
TO IMPLEMENT OPERATIONS
ON DOUBLE LINKED LIST USING SELFREFERENTIAL CLASSES.*/



#include<iostream.h>
int  count=0;
class
dll   //CLASS
DECLARATION

{
private:
   char
data[11];

   dll
*left,*right;//DATA
MEMBERS

public:
   
void inser_end( char[] );

   
void show();

} *head;

//FUNCTION
FOR INSERTING NODE AT THE END

void dll::inser_end(char
s[])

{
   
dll *n,*temp;

   
n=new(dll);

   
for(int i=0;s[i]!=”;i++)

   
n->data[i]=s[i];

   
n->data[i]=”;

   
n->left=NULL;

   
n->right=NULL;

   
if(head==NULL)

   
    head=n;

   
else

   
{

   
temp=head;

   
while(temp->right!=NULL)

   
{

   
temp=temp->right;

   
}

   
temp->right=n;

   
n->left=temp;

   
}

}

//FUNCTION FOR DISPLAY

OUTPUT   
   
void dll::show()
{
   
count=0;

   
dll *temp;

  if(head==NULL)
 
cout<<“NO NODES IN THE LIST  “;

  else
  {
 temp=head;
 while(temp!=NULL)
  {
  count++;
 
cout<<temp->data<<endl;

 
temp=temp->right;

   }
}
cout<<“THE
NO OF NODES ->”<<count<<endl;

}

void  main()//MAIN() FUNCTION

STARTS
{
   
char x[22];

   
int p;

   
head=NULL;

   
dll d;//OBJECT
CREATION

   
cout<<“ENTER THE NO OF STRINGS

          &nbs

p;
TO BE INSERTED AT THE END”;
   
cin>>p;

   

   
cout<<“ENTER THE
“<<p<<”  STRINGS”;

   
for(int i=0;i<p;i++)

   
{

   
cin>>x;

   
d.inser_end(x);

   
}

   
cout<<“AFTER INSERTING AT

          &nbs

p; 
THE END THE LIST IS\n”;

   
d.show();

}//END OF MAIN()

//PROGRAM
ENDS

/* OUTPUT:
ENTER
THE NO OF STRINGS TO

 BE
INSERTED AT THE END 5

ENTER
THE 5  STRINGS

BHANU
PHANISRI
SURENDRA
DBNRAO
BUJJI
AFTER
INSERTING AT THE

     
END THE LIST IS

BHANU
PHANISRI
SURENDRA
DBNRAO
BUJJI
THE
NO OF NODES ->5

Press
any key to continue

*/

HOME

DLL_INSERTION_AT_FRONTEND

March 27, 2008

HOME
/*
 PROGRAM TO IMPLEMENT OPERATIONS

 
ON DOUBLE LINKED LIST USING SELFREFERENTIAL CLASSES   */


#include<iostream.h>
int 
count=0;

class
dll  
//CLASS DECLARATION

{
private:
  
char data[11];

  
dll *left,*right;//DATA
MEMBERS

public:
  
 

  
 void inser_beg(char[ ] );//MEMBER FUNCTIONS

  
 

  
 void show();

}
*head;

/*FUNCTION
FOR INSERTING NODE
 AT THE BEGINNIN*/

{

void dll::inser_beg(char s1[ ])

  
 dll *n,*temp;

  
 n=new(dll);

  
 for(int i=0;s1[i]!=”;i++)

  
 n->data[i]=s1[i];

  
 n->data[i]=”;

  
 n->right=NULL;

  
 n->left=NULL;

  
 if(head==NULL)

  
     head=n;

  
 else

  
 {

  
 temp=head;

  
 n->right=temp;

  
 temp->left=n;

  
 head=n;

  
 }

}
  
 

  
     

void
dll::show()//FUNCTION
FOR DISPLAY OUTPUT

{
   
count=0;

  
 dll *temp;

  
 if(head==NULL)

  
     cout<<“NO NODES
IN THE LIST  “;

  
 else

  
 {

  
 temp=head;

  
 while(temp!=NULL)

  
 {

  
 count++;

  
 cout<<temp->data<<endl;

  
 temp=temp->right;

  
 }

  
 }

cout<<“THE
NO OF NODES ->”<<count<<endl;

}

void 
main()//MAIN()
FUNCTION STARTS

{
 char
x[22];

 head=NULL;
 int
p;

 dll
d;//OBJECT

CREATION
 cout<<“ENTER
THE NO OF STRINGS

 TO
BE INSERTED AT THE BEGINNING”;

 cin>>p;
  
 

 cout<<“ENTER
THE “<<p<<”  STRINGS”;

 for(int
i=0;i<p;i++)

 {
 
cin>>x;

 d.inser_beg(x);
 }
 cout<<“AFTER
INSERTING AT

 THE
FIRST POSOTION THE LIST IS\n”;

 d.show();
  
 

 } //END OF MAIN()

//PROGRAM
ENDS

/*
OUTPUT:
ENTER
THE NO OF STRINGS TO BE

   
INSERTED AT THE BEGINNING

4
ENTER
THE 4  STRINGS

BHANU
DURGA
KRTHEEK
LAKSHMI
AFTER
INSERTING AT THE FIRST

    
POSOTION THE LIST IS

LAKSHMI
KRTHEEK
DURGA
BHANU
THE
NO OF NODES ->4

Press
any key to continue

*/

HOME