المقيمي
05-10-2009, 03:01 PM
#include<iostream>
using namespace std;
struct employee
{
int emp_id;
float emp_salary;
struct employee * llink;
struct employee * rlink;
};
void main()
{
struct employee n,*temp,*a,*t,*sort,*sortow;
char ch='y';
int count='0' ,i='0';
int j,h,id,num;
float salary;
n.rlink=NULL;
n.llink=NULL;
temp=&n;
sort=&n;
t=&n;
while(ch=='y')
{
a=(employee *)malloc(sizeof(employee));
cout<<"Enter the ID:::";
cin>>a->emp_id;
cout<<"Enter the Salary:::";
cin>>a->emp_salary;
a->llink=NULL;
a->rlink=NULL;
t->llink=a;
a->rlink=t;
t=t->llink;
cout<<"Want to continue(y/n)::";
cin>>ch;
}
cout<<"The elements in the forward traversal is(L to R)::"<<endl;
temp=temp->llink;
t->llink=temp;
temp->rlink=t;
sort=temp;
num=i;
for (j=0;j<num;j++)
{
sortow=sort->llink;
for(h=0;h<j;h++)
{
if (sort->emp_id <sortow->emp_id)
{ id=sort->emp_id ;
salary=sort->emp_salary ;
sort->emp_id =sortow->emp_id ;
sort->emp_salary =sortow->emp_salary ;
sortow->emp_id =id;
sortow->emp_salary =salary;
sortow=sortow->llink ;
}
}
sort=sort->llink;
}
while(count!=i+10)
{
cout<<temp->emp_id <<"\t";
cout<<temp->emp_salary<<endl;
temp=temp->llink;
count++;
}
cout<<"The elements in the reverse traversal is(R to L)::"<<endl;
count='0';
while(count!=i+10)
{
cout<<t->emp_id<<"\t";
cout<<t->emp_salary<<endl;
t=t->rlink;
count++;
}
}
using namespace std;
struct employee
{
int emp_id;
float emp_salary;
struct employee * llink;
struct employee * rlink;
};
void main()
{
struct employee n,*temp,*a,*t,*sort,*sortow;
char ch='y';
int count='0' ,i='0';
int j,h,id,num;
float salary;
n.rlink=NULL;
n.llink=NULL;
temp=&n;
sort=&n;
t=&n;
while(ch=='y')
{
a=(employee *)malloc(sizeof(employee));
cout<<"Enter the ID:::";
cin>>a->emp_id;
cout<<"Enter the Salary:::";
cin>>a->emp_salary;
a->llink=NULL;
a->rlink=NULL;
t->llink=a;
a->rlink=t;
t=t->llink;
cout<<"Want to continue(y/n)::";
cin>>ch;
}
cout<<"The elements in the forward traversal is(L to R)::"<<endl;
temp=temp->llink;
t->llink=temp;
temp->rlink=t;
sort=temp;
num=i;
for (j=0;j<num;j++)
{
sortow=sort->llink;
for(h=0;h<j;h++)
{
if (sort->emp_id <sortow->emp_id)
{ id=sort->emp_id ;
salary=sort->emp_salary ;
sort->emp_id =sortow->emp_id ;
sort->emp_salary =sortow->emp_salary ;
sortow->emp_id =id;
sortow->emp_salary =salary;
sortow=sortow->llink ;
}
}
sort=sort->llink;
}
while(count!=i+10)
{
cout<<temp->emp_id <<"\t";
cout<<temp->emp_salary<<endl;
temp=temp->llink;
count++;
}
cout<<"The elements in the reverse traversal is(R to L)::"<<endl;
count='0';
while(count!=i+10)
{
cout<<t->emp_id<<"\t";
cout<<t->emp_salary<<endl;
t=t->rlink;
count++;
}
}