Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
TempQuickDoubArray2
//g++ 7.4.0 //Sorting template array using quick sort & double linked list //code is created by Rezaul Hoque on March 20,2021 //please contact at jewelmrh@yahoo.com #include <iostream> #include <bits/stdc++.h> using namespace std; template <class T> class node{ public: T val; int p; int q; 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<char>* a; a = new node<char>[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={'E'}; a[1].val={'D'}; a[2].val={'C'}; a[0].p={4}; a[1].p={2}; a[2].p = {6}; a[0].q={5}; a[1].q={4}; a[2].q = {8}; cout<<"Before quick sort:\n"; for(int i=0; i<max; i++) { cout<<a[i].val<<"\t"<<a[i].p<<"\t"<<a[i].q<<endl; cout<<"\n"; } cout<<"After quick sort:\n"; a->quick(a, 0, max-1); for(int i=0; i<max; i++) { cout<<a[i].val<<"\t"<<a[i].p<<"\t"<<a[i].q<<endl; cout<<"\n"; } return 0; }
run
|
edit
|
history
|
help
0
template
NameAdTel
Microsoft - MaxEmployeeAttendence (R repititions - DP solution bitmask)
offsetof
Test1
find first non repeating
Stream4
Decimal to Binary
typeid
2015(M2)Mod.