Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BubDoubArray
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 //Templated Bubble Sort in Double Linked List ( Using Arrat) //code is created by Rezaul Hoque on March 12 on 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 bubble(node<T> a[], T n) { T temp, i,j; for (T i=0; i<n; i++) { for (T j=0; j<n; j++) { if( a[i].val < a[j].val){ temp = a[i].val; a[i].val = a[j].val; a[j].val = temp; } } } } }; 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<3; i++) { a[i].next = a[i+1].prev; a[i].prev = a[i-1].next; } a[0].val={5}; a[1].val={4}; a[2].val={2}; cout<<"After bubble sort:\n"; a->bubble(a,3); for (int i= 0; i<max; i++) { cout<<" "<<a[i].val; } return 0; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 1.33 sec, absolute running time: 0.15 sec, cpu time: 0.01 sec, memory peak: 5 Mb, absolute service time: 1,53 sec
latest
|
history
After bubble sort: 2 4 5