Posts

Sort LL in blocks of K

struct node* SortLL(struct node* head) { struct node* temp; struct node* orighead; struct node* minnode; int current, min, swap; temp = head; orighead = head; if(head == NULL) return NULL; if(head-> next == NULL) return head; while(head != NULL) { temp = head; current = temp->data; min = current; temp = temp->next; while(temp != NULL) { if(min > temp->data) { min  = temp->data; minnode = temp; } temp = temp->next; } if(current > min) { //swap the two values swap = head->data; head->data = minnode->data; minnode->data = swap; } head = head->next; } return orighead; } struct node* SortLLinBlockK(struct node* head, int k) { struct node* nexthead = head; struct node* orighead = head; struct node* temp; int i; k=k-1; while(head != NULL) { for( i = 0; i<k; i++) { nexthead = nexthead->next; if (n...