728x90 AdSpace

Latest Article

Link list with Queue and bubble sort in C++ Sample Code




How to Create a Link list with Queue and bubble sort in c++ Programming language data structure
#include<iostream.h>
#include<conio.h>
class node
 {
  public:
      int data;
      node *address;
 };
   void main(void)
   {
     node *handler=new node();
     node *temp1=new node();
     node *temp2=new node();
     node *temp3=new node();
     char ch;
     int save;
     clrscr();
//////////////////////CREATE LINKLIST WITH QEUEU//////////
     node *n1=new node();
     node *temp=new node();
     handler=n1;
     n1->address=NULL;
     cout<<"INSERT DATA  :";
     cin>>n1->data;
     temp=n1;
     cout<<"To insert more data press Y"<<endl;
     ch=getch();
       while(ch=='y')
 {
   node *n1=new node();
   cout<<"INSERT DATA  :";
   cin>>n1->data;
   n1->address=NULL;
   temp->address=n1;
   temp=n1;
   cout<<"To insert more data press Y"<<endl;
   ch=getch();
 }
/////////////////////////OUTPUT//////////////////////
 temp1=handler;
 cout<<"THE OUTPUT IS";
  while(temp1)
   {
    cout<<endl;
    cout<<temp1->data;
    temp1=temp1->address;
   }
/////////////////////BUBBLE SORT///////////////////////
temp=handler;
cout<<endl<<"SORTING BUBBLE:";
while(temp->address)
{
 temp2=handler;   ///intilize with start
 while(temp2->address)
 {
    temp3=temp2->address;
    if(temp2->data>temp3->data)
    {
      save=temp2->data;
      temp2->data=temp3->data;
      temp3->data=save;
    }
    temp2=temp2->address;
  }
 temp=temp->address;
}
//////
temp=handler;
cout<<"\n\nBUBBLE SORT OUTPUT\n";
while(temp)
{
 cout<<endl;
 cout<<temp->data;
 temp=temp->address;
}
getch();
}
no image





  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment

Top