19.2 Sybsc CS SPPU DS Practical Slip Solutions
19.2 Sybsc CS SPPU DS Practical Slip Solutions
There are lists where insertion should ensure the ordering of data elements. Since the elements are in
ascending order the search can terminate once equal or greater element is found. Implement a singly
linked list of ordered integers (ascending/descending) with insert, search and display operations.
#include<stdio.h>
#include<stdlib.h>
Struct node
Int data;
};
Int I;
F = newnode;
Scanf(“%d”,&f->data);
S = f;
For(i=2;i<=n;i++)
s->next = newnode;
s = s->next;
s->next=NULL;
return f;
Printf(“\t %d”,t->data);
Int cnt=0,I;
Cnt++;
If(p>=cnt)
Else
S=newnode;
Printf(“\n Enter the data :”);
Scanf(“%d”,&s->data);
If(p==1)
s->next = f;
f=s;
Else
For(i=1,t=f;i<=p-2;i++)
T=t->next;
s->next = t->next;
t->next = s;
Return f;
Int temp;
For(p=f;p!=NULL;p=p->next)
For(q=p->next;q!=NULL;q=q->next)
{
Temp=p->data;
p->data=q->data;
q->data=temp;
Main()
Int n,p,p1,ch;
Do
Printf(“\n\n 1.create link list \n 2. Display \n 3.insert into link list \n 4.sorted order \n
0.exit “);
Scanf(“%d”,&ch);
Switch(ch)
Case 1 :printf(“\n Enter how manu elements you wnt to enter :”);
Scanf(“%d”,&n);
L=create(n);
Break;
Case 2 : display(l);
Break;
Scanf(“%d”,&p);
L=insert(l,p);
Break;
Case 4:sort(l);
Break;
Case 0 :exit(0);
while(ch!=0);