Posts

Showing posts with the label Program to sort a linked list by readjusting the links.

Program to sort a linked list by readjusting the links.

#include #include #include /* structure containing a data part and link part */ struct node { int data ; struct node *link ; } *start, *visit ; void getdata( ) ; void append ( struct node **q, int num ) ; void displaylist( ) ; void selection_sort( ) ; void bubble_sort( ) ; void main( ) { getdata( ) ; clrscr( ) ; printf ( "\nLinked List Before Sorting:\n" ) ; displaylist( ) ; selection_sort( ) ; printf ( "\nLinked List After Selection Sorting:\n" ) ; displaylist( ) ; getch( ) ; getdata( ) ; clrscr( ) ; printf ( "\nLinked List Before Sorting:\n" ) ; displaylist( ) ; bubble_sort( ) ; printf ( "\nLinked List After Bubble Sorting:\n" ) ; displaylist( ) ; getch( ) ; } void getdata( ) { int val, n ; char ch ; struct node *newnode; clrscr( ) ; newnode = NULL ; do { printf ( "\nEnter a value: " ) ; scanf ( "%d", &val ) ; append ( &newnode, val ) ; printf ( "\nAny More Nodes (Y/N): " ) ...