-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.c
63 lines (62 loc) · 859 Bytes
/
new.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<stdio.h>
#include<stdlib.h>
#include"linklist.h"
void sort();
int count()
{
ptr= head;
int c=1;
while (ptr->next!= NULL)
{
c++;
ptr=ptr->next;
}
return c;
}
void main()
{
int ch;
do
{
printf("\n1.Create");
printf("\n2.Display");
printf("\n3.Sort");
printf("\n4.Exit");
printf("\nEnter your choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:create();
break;
case 2:display();
break;
case 3:sort();
break;
case 4:exit(0);
}
}
while(ch!=4);
}
void sort()
{
int i,j,n,k;
struct node *temp1,*temp2;
n = count();
for(i=n-2;i>=0;i--)
{
temp1=head;
temp2=temp1->next;
for(j=0;j<=i;j++)
{
if(temp1->data > temp2->data)
{
k=temp1->data;
temp1->data=temp2->data;
temp2->data=k;
}
temp1=temp2;
temp2=temp2->next;
}
}
display();
}