void verifySolution() { Node*list = new Node(); Node *tmp = list; tmp->d = 3; tmp->next = new Node(); tmp = tmp->next; tmp->d = 6; tmp->next = new Node(); tmp = tmp->next; tmp->d = 3; tmp->next = new Node(); tmp = tmp->next; tmp->d = 4; tmp->next = new Node(); tmp = tmp->next; tmp->d = 5; tmp->next = new Node(); tmp = tmp->next; tmp->d = 3; tmp->next = NULL; auto start = std::chrono::steady_clock::now(); partitionList(&list, 5); printList(list); partitionList(&list, 4); printList(list); auto end = std::chrono::steady_clock::now(); auto diff = end - start; std::cout << std::endl; std::cout << "Microseconds: " << std::chrono::duration <double,std::micro> (diff).count() << " us" << std::endl; checkPartition(4,list); }
int main(int argc, char** argv) { const int LIST_SIZE = 8; int partIdx; for (partIdx = LIST_SIZE - 1; partIdx >= 0; --partIdx) { node *head = NULL, *prev = NULL; int count; for (count = 1; count <= LIST_SIZE; ++count) { node* n = add(count, prev); if (!head) { head = n; } prev = n; } printf("\nInitial linked list; partitioning at idx %d\n", partIdx); output(head); node* second = NULL; node* first = partitionList(head, partIdx, &second); printf("\nFirst partition\n"); output(first); printf("\nSecond partition\n"); output(second); release(first); release(second); } return 0; }
void quickSortList(ListNode* head, ListNode* end) { if(head == NULL || head == end) return ; // no element if(head -> next == NULL || head -> next == end || head -> next -> next == end) return ; pair<ListNode*, ListNode*> p = partitionList(head, end); quickSortList(head, p.first); quickSortList(p.second, end); }
int main() { Node head = nodeCreate(10); printf("2. The list and the linked list is now:\n"); int array[] = {9,8,7,6,5,4,3,2,1}; for(int i = 0; i < 9; i++) { head = listAppend(head, array[i]); } Node item = head; while(item->next != NULL) { printf("%d ", item->num); item = item->next; } printf("%d\n\n\n\n", item->num); head = partitionList(head, 9); item = head; while(item->next != NULL) { printf("%d ", item->num); item = item->next; } printf("%d\n\n\n\n", item->num); return 0; }