// making below link list as a ordered linked list
// NOTE:- i have used TURBO C/C++ compiler
// please replay soon with error explanation thank you in advance
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
struct link
{
int num;
struct link *next;
};
typedef struct link node;
node *start = NULL;
node *put,*temp,*disp;
void create()
{
int n;
put=(node*)malloc(sizeof(node));
cout<<"\n Enter no.";
cin>>n;
put->num=n;
put->next=NULL;
}
void insert(node *put)
{
if(start==NULL)
{
start=put;
temp=start;
disp=start;
}
while(disp!=NULL)
{
if((disp->num) > (put->num))
{
temp->next=put;
temp=put;
}
}
{
temp->next=put;
temp=put;
}
}
void display(node *disp)
{
cout<<"\n Displaying List:";
while(disp!=NULL)
{
cout<<disp->num<<"->";
disp=disp->next;
}
}
void main()
{
clrscr();
char ch;
prg:
cout<<"\n Do you want to create (Y/N):";
cin>>ch;
if( ch=='y' || ch=='Y')
{
create();
insert(put);
display(disp);
goto prg;
}
else
{
exit(0);
}
getch();
}

New Topic/Question
Reply




MultiQuote




|