Hello All,

Following is the bubble sorting program. It is crashing is sort function. Please let me know, where I;m goig wrong.

Code:# include <stdio.h> # include <stdlib.h> void append(struct node **,struct node *); void display(struct node *); int Delete_nth_node(struct node **,int i); void sort(struct node **); void delTree(struct node *); //struct node *merge_list(struct node **ppHead1,struct node **ppHead2); //struct node *merge(struct node *current1,struct node *current2); //int length(struct node *walk); struct node { int data; struct node *next; }node; void main(void) { int i, result; struct node *pHead1, *new_node; pHead1 = NULL; printf("Enter the numbers for list 1:\n"); if ( scanf("%d",&i) == 1 ) { while (i) { new_node = calloc(1,sizeof(node)); new_node->data = i; append(&pHead1,new_node); if ( scanf("%d",&i) == 1 ) continue; else break; } display(pHead1); } // printf("\nAfter deleting 2nd node\n"); // result = Delete_nth_node(&pHead1,2); // if ( result ) // display(pHead1); sort(&pHead1); display(pHead1); delTree(pHead1); } void sort(struct node **ppHead) { struct node *current,*forward,*save; current = *ppHead; forward = current->next; save = NULL; while(current) { while(forward) { if (current->data > forward->data) { struct node *temp; temp = forward->next; forward->next = current; current->next = temp; forward = temp; if (save) save->next = current; } else forward = forward->next; } save = current; current = current->next; forward = current->next; } } // Inserts, appends or prepends depending upon its value. void append(struct node **ppHead, struct node *new_node) { struct node *current; // First time when not even single node is generated if ( *ppHead == NULL ) { new_node->next = NULL; *ppHead = new_node; } else { current = *ppHead; while (current->next != NULL) current = current->next; current->next = new_node; } } int Delete_nth_node(struct node **ppHead,int i) { struct node *current,*nth_node,*save; nth_node = NULL; current = *ppHead; while ( current ) { if ( current == NULL && (!nth_node) ) return 0; else if ( !i ) { save = nth_node = *ppHead; while (1) { if ( current->next == NULL ) break; current = current->next; save = nth_node; nth_node = nth_node->next; } if ( save == nth_node) { *ppHead = save->next; return 1; } save->next = nth_node->next; free(nth_node); return 1; } current = current->next; i--; } return 0; } // Displays entire link list void display(struct node *walk) { printf("\nLink list is:\n"); while (walk) { printf("%d\t",walk->data); walk = walk->next; } } void delTree(struct node *walk) { struct node *save; while (walk) { save = walk->next; free(walk); walk = save; } }