Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
QuickDoubly
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 1.93 sec, absolute running time: 0.19 sec, cpu time: 0.02 sec, memory peak: 5 Mb, absolute service time: 2,24 sec
edit mode
|
history
|
discussion
2 3 5 8 10