Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BubbleDouble
//g++ 7.4.0 //BubbleDouble: Bubble Sort in Doubly Linked List //code credit codesdope and prodevelopertutorial #include <iostream> #include <bits/stdc++.h> using namespace std; class node { public: int val; node *next; node *prev; }; void swap(node * left, node* right) { int temp = left->val; left->val = right->val; right->val= temp; } void bubble(node* left)//credit prodevelopertutorial { int swapon; node *leftpt; node *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 *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; bubble(head); while (head != NULL) { cout<<" "<<head->val; head = head->next; } return 0; }
run
|
edit
|
history
|
help
0
cons1
Two pointer - MUST DO
javascript style arrays in c++
Problem: binary
Binary Search
Right view of a tree
¡Arriba, Papalotes, Arriba!
шаблонизированное наследование
test
Funny Saying