diff --git a/sort.c b/sort.c new file mode 100644 index 0000000..47c1c1b --- /dev/null +++ b/sort.c @@ -0,0 +1,53 @@ +#include +#include +typedef struct node{ +int data; +struct node*next; +}node; +void main() +{ node*head,*p,*q,*h2; + int i,n,ch,flag,x,val; + printf("Enter the number of nodes\n"); + scanf("%d",&n); +head=(node*)malloc(sizeof(node)); +printf("Enter data for first node\n"); +scanf("%d",&head->data); +head->next=NULL; +p=head; +for(i=0;inext=(node*)malloc(sizeof(node)); +p=p->next; +printf("enter data for new node\n"); +scanf("%d",&p->data); +p->next=NULL; +} +// PRINTING +p=head; +while(p!=NULL) +{ printf("%d\t",p->data); +p=p->next; +} + +p=head; +while(p->next!=NULL){ + for(q=p->next;q!=NULL;q=q->next){ + if(p->data > q->data){ + x=p->data; + p->data=q->data; + q->data=x; + } + else{ + p=p->next; + } + } +} + +printf("\nSorted\n"); +p=head; +while(p!=NULL) +{ printf("%d\t",p->data); +p=p->next; +} + +} +