Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
TempQuickDoubArray
//g++ 7.4.0 //Quick Sort in Double Linked List (using array) //code is created by Rezaul Hoque on March 18,2021 //please contact at jewelmrh@yahoo.com #include <iostream> #include <bits/stdc++.h> using namespace std; template <class T> class node{ public: T val; node<T>* next; node<T>* prev; void swap(node<T>& p, node<T>& q); void quick(node<T> a[],T low, T high); T part(node<T> a[],T low, T high); }; template <class T> void node<T>::swap(node<T>& p, node<T>&q ) { node<T> temp; temp = p; p = q; q = temp; } template <class T> T node<T>::part(node<T> a[],T low, T high){ T pivot = a[high].val; T i = (low - 1); for (T j = low; j <= high- 1; j++) { if (a[j].val <= pivot) { i++; swap(a[i], a[j]); } } swap(a[i + 1], a[high]); return (i + 1); } template <class T> void node<T>::quick(node<T> a[], T low, T high) { if (low < high) { T pi = part(a, low, high); quick(a, low, pi - 1); quick(a, pi + 1, high); } } int main() { const int max=3; node<int>* a; a = new node<int>[max]; a[0].prev=NULL; a[2].next = NULL; for(int i=0; i<max; i++) { a[i].next = a[i+2].prev; } a[0].val={5}; a[1].val={4}; a[2].val={2}; cout<<"After quick sort:\n"; a->quick(a, 0, max-1); for(int i=0; i<max; i++) { cout<<" "<<a[i].val; } return 0; }
run
|
edit
|
history
|
help
0
.
big boom!
find parent count of node in graph
Matrix rotation
str_to_int
combine c++ string with dynamically allocated c array of chars through overloaded add operator
Microsoft - MaxEmployeeAttendence (R repititions - 1st step towards DP.)
A • Potato Sacks
Default_Template
c++