Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
TempBubbleDouble
//g++ 7.4.0 //Templated Bubble Sort in Double Linked List //code credit internet // template modifications by Rezaul Hoque on March 10,2021 #include <iostream> #include <bits/stdc++.h> using namespace std; template <class T> class node { public: T val; node<T> *next; node<T> *prev; }; template <class T> void swap(node<T> * left, node<T>* right) { T temp = left->val; left->val = right->val; right->val= temp; } template <class T> void bubble(node<T>* left)//credit prodevelopertutorial { int swapon; node<T> *leftpt; node<T> *rightpt = NULL; do { swapon = 0; leftpt = left; while(leftpt->next != rightpt) { if (leftpt->val > leftpt->next->val) { swap(leftpt, leftpt->next); swapon = 1; } leftpt = leftpt->next; } rightpt = leftpt; }while(swapon); } int main() { node<int > *head = (node<int>*) malloc(sizeof( node<int>)); head->val = 2; head->prev = NULL; node<int > *l1 = (node<int>*) malloc(sizeof( node<int>)); l1->val = 8; l1->prev = head; head->next = l1; node<int> *l2 = (node<int>*) malloc(sizeof( node<int>)); l2->val = 3; l2->prev = l1; l1->next = l2; node<int>*l3 = (node<int>*) malloc(sizeof( node<int>)); l3->val = 5; l3->prev = l2; l2->next = l3; node<int> *l4 = (node<int>*) malloc(sizeof( node<int>)); l4->val = 10; l4->prev = l3; l3->next = l4; l4->next = NULL; node<char>* chead = (node<char>*)malloc(sizeof(node<char>)); chead->val='G';chead->prev = NULL; node<char>* cl1 = (node<char>*)malloc(sizeof(node<char>)); cl1->val = 'E'; cl1->prev = chead; chead->next = cl1; node<char>* cl2= (node<char>*)malloc(sizeof(node<char>)); cl2->val = 'H'; cl2->prev = cl1; cl1->next= cl2; node<char>* cl3 = (node<char>*)malloc(sizeof(node<char>)); cl3->val = 'F'; cl3->prev = cl2; cl2->next= cl3; node<char>* cl4 = (node<char>*)malloc(sizeof(node<char>)); cl4->val= 'A'; cl4->prev = cl3; cl3->next= cl4; cl4->next = NULL; cout<<"After bubble sort:\n"; bubble(head); while (head != NULL) { cout<<" "<<head->val; head = head->next; } cout <<endl; bubble(chead); while (chead != NULL) { cout<<" "<<chead->val; chead = chead->next; } return 0; }
run
|
edit
|
history
|
help
0
Vector
Hello
BubDoubArray2
Find the row with max ones
data locality - slow example
10 wizards-DFS_vector
PriQTel2
TwoVarRegression
articulation points (http://codeforces.com/contest/732/problem/F)
Microsoft - MaxEmployeeAttendence (R repititions - DP solution bitmask)