data structures - Sort a Linked list using C - Stack Overflow
stackoverflow.com › questions › 40623432Nov 16, 2016 · I have seen some programs too, which sort linked list and their approach is also like this only. #include <stdio.h> #include <stdlib.h> 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 ...
Sorting a linked list in C - Stack Overflow
stackoverflow.com › questions › 11813696Aug 05, 2012 · In this function,a node whose data is the smallest in the list is made as 'head' node(i.e. starting node of the list) by scanning the whole list once.Then from the remaining list,again a node with the smallest data is found out whose address is kept in the 'next' field of previous node(head node).This process continues to sort the whole list.