diff --git a/sortalist.c b/sortalist.c new file mode 100644 index 0000000..e46fd26 --- /dev/null +++ b/sortalist.c @@ -0,0 +1,61 @@ +#include +#include + +struct node { + int data; + struct node *next; +}; + +int push(struct node **h, int x) +{ + struct node *temp = (struct node*)malloc(sizeof(struct node)); + temp->data = x; + temp->next = *h; +*h = temp; + return 0; +} + +void print(struct node *head) +{ + struct node *temp = head; + while(temp != NULL) + { + printf("%d ",temp->data); + temp = temp->next; + } + printf("\n"); +} + +void sort(struct node **h) +{ + int i,j,a; + + struct node *temp1; + struct node *temp2; + + for(temp1=*h;temp1!=NULL;temp1=temp1->next) + { + for(temp2=temp1->next;temp2!=NULL;temp2=temp2->next) + { + a = temp1->data; + temp1->data = temp2->data; + temp2->data = a; + } + } +} + +int main() +{ + struct node * head = NULL; + push(&head,5); + push(&head,4); + push(&head,6); + push(&head,2); + push(&head,9); + printf("List is : "); + print(head); + sort(&head); + printf("after sorting list is : "); + print(head); + return 0; +} diff --git a/string.c b/string.c index 4aaf9b4..54d8a2c 100644 --- a/string.c +++ b/string.c @@ -1,9 +1,9 @@ #include -int main() +void main() { char name[20]; printf("Enter name "); scanf("%s",name); printf("Your name is %s",name); - return 0; -} \ No newline at end of file + +}