Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
QuickDoubly
//g++ 7.4.0 //Quick Sort in Double Linked List //code credit codesdope #include <iostream> #include <bits/stdc++.h> using namespace std; class node { public: int val; node *next; node *prev; }; node *partition( node *left, node *right) { node *pivot = right; node *i = left->prev; for ( node *ptr = left; ptr != right; ptr = ptr->next) { if (ptr->val <= pivot->val) { i = (i == NULL ? left : i->next); int temp = i->val; i->val = ptr->val; ptr->val = temp; } } i = (i == NULL ? left : i->next); int temp = i->val; i->val = pivot->val; pivot->val = temp; return i; } void QuickSort( node *left, node *right) { if (right != NULL && left != right && left != right->next) { node *p = partition(left, right); QuickSort(left, p->prev); QuickSort(p->next, right); } } int main() { node *head =(node*)malloc(sizeof(node)); head->val = 2; head->prev = NULL; node *l1 =(node*)malloc(sizeof(node)); l1->val = 8; l1->prev = head; head->next = l1; node *l2 = (node*) malloc(sizeof( node)); l2->val = 3; l2->prev = l1; l1->next = l2; node *l3 = (node*) malloc(sizeof( node)); l3->val = 5; l3->prev = l2; l2->next = l3; node *l4 = (node*) malloc(sizeof( node)); l4->val = 10; l4->prev = l3; l3->next = l4; l4->next = NULL; QuickSort(head, l4); while (head != NULL) { cout<<" "<<head->val; head = head->next; } return 0; }
run
|
edit
|
history
|
help
0
WeekAgenda
Kalkulator z bajerami
MinCostKStops_DFS
water drop/ water land
Intersected Rectangles
test
extern
Привет Linux
Polimorfizm :)
Yo que se