DLL_INSERTION_AT_REAREND

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: