can someone please help me to create a simple c++ program: linked list that will insert a node and sort it then display
struct Node{
int data;
Node *link;
};
thanks in advance for your help
i hope it help
struct Node
{
int data;
Node *link;
};
void main()
{
int * temp;
node *p;
p=new Node;
cout<<"enter node";
cin>>p->data;
p->link=NULL;
cout<<" "<<p->data<<endl;
node *q;
q=new Node;
cout<<"ENTER again:";
cin>>q->data;
q->link=NULL;
if (p->data < q->data)
{
temp=p->data;
p->data=q->data;
q->data=temp;
cout<<"\n"<<p->data<<"="<<q->data;
}
else
{
cout<<"="<<p->data<<"="<<q->data;
}
NODE *x;
x=new Node;
cout<<"\n\aONE MORE ELEMENT::";
cin>>x->data;
x->elink=NULL;
if( p->data > q->data && p->data > x->data)
{
if( q->data > x->data)
{
cout<<"="<<p->data<<"="<<q->data<<"="<<x->data;
}
else
{
cout<<"="<<p->data<<"="<<x->data<<"="<<q->data;
}
}
else if (q->data > p->data && q->data>x->data)
{
if ( p->data > x->data)
{
cout<<"="<<q->data<<"="<<p->data<<"="<<x->data;
}
else
{
cout<<"="<<q->data<<"="<<x->data<<"="<<p->data;
}
}
else if ( x->data > p->data && x->data > q->data)
{
if ( p->data> q->data)
{
cout<<"="<<x->data<<"="<<p->data<<"="<<q->data;
}
else
{
cout<<"="<<x->data<<"="<<q->data<<"="<<p->data;
}
}
i hope it help..i`d try my best! :D