size_t partions_pairs(double l[], long k[], size_t low, size_t high) { double prvotkey=l[low]; while (low<high) { while (low<high && l[high]>=prvotkey) --high; swap_pairs(l, k, high, low); while (low<high && l[low]<=prvotkey) ++low; swap_pairs(l, k, high, low); } return low; }
int main_5(void){ int i=1, list_sz=6; struct list_node *list = (struct list_node*)calloc(6, sizeof(struct list_node)); struct list_node *node = list; struct list_node *list_end = list + list_sz; while(node != list_end){ node->val = i++; node->next = node+1; node++; } //non-circular list (node-1)->next=NULL; //circular list //(node-1)->next=list; node = list; while(node != list_end){ printf("%d -> ", node->val); node++; } printf("||\n"); struct list_node *new_list = swap_pairs(list); node = new_list; while(node != NULL){ printf("%d -> ", node->val); node = node->next; if(node == new_list){ printf(" [Circular List] -> ... -> "); break; } } printf("||\n"); return 0; }