Print Friendly and PDF
#include<iostream> 
#include<conio.h> 
using namespace std; 
struct node 
{ 
int data; 
node *Rptr; 
node* Lptr; 
}; 
node* head=NULL; 
node* current = NULL; 
int main() 
{ 
int counter,i,j,gap,temp; 
char option; 
option='y'; 
counter=0; 
while(option=='y' || option=='Y') 
{ 
node* a = new node; 
cout<<"enter Data : "; 
cin>>a->data; 
if(head==NULL) 
{ 
a->Lptr=NULL; 
a->Rptr=NULL; 
head=current=a; 
} 
else 
{ 
current->Rptr=a; 
a->Lptr=current; 
a->Rptr=NULL; 
current=a; 
} 
counter++; 
cout<<"Do You Want to create another variable ??? (y/n) : "; 
cin>>option; 
} 
cout<<"The total number of nodes is: "<<counter<<endl; 
int *array = new int[counter]; 
i=0; 
while(head != NULL) 
{ 
array[i++] = head->data; 
head = head->Rptr; 
} 
for(gap=counter/2; gap > 0; gap /= 2) 
{ 
for(i=gap; i < counter; i++) 
{ 
temp = array[i]; 
for(j = i; j >= gap; j -=gap) 
{ 
if(temp < array[j-gap]) 
array[j] = array[j-gap]; 
else 
break; 
} 
array[j] = temp; 
} 
} 
//after sortng data; 
cout<<"sorted data is"<<endl; 
for(i=0; i<counter;i++) 
{ 
cout<<array[i]<<" "; 
} 
system("pause"); 
}
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: