Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
completeBubbleSort
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
// // main.cpp // Bubble Sort // // Created by Kevin Lopez on 5/17/17. // Copyright © 2017 Kevin Lopez. All rights reserved. // //#include <array> #include <iostream> using namespace std; int main() { int i; int hold; int number[] = {900, 0, 3, -1, -9, 7, -29, -59}; int lenghOfArray = sizeof(number)/sizeof(number[0]); // Finds the correct starting index for (i = 0; i < lenghOfArray; i++) { // Should be using abs (absolute); from framework instead of this workaround if (number[i] || number[i] * -1) { break; } } // At this point we know that the number[i] is not negative // So all this does is performs the swap, a && a + 1 while(i <= lenghOfArray) { for (int a = 0; a < lenghOfArray; a++) { if (number[a] > number[a + 1]) { // could use XOR swap to save memory hold = number[a]; // x=x^y number[a] = number[a + 1]; // y=x^y number[a + 1] = hold; // x=x^y } } i++; } for (int c = 0; c < lenghOfArray; c++) { cout << number[c]; cout << "\n"; } return 0; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.32 sec, absolute running time: 0.14 sec, cpu time: 0 sec, memory peak: 3 Mb, absolute service time: 0,55 sec
edit mode
|
history
|
discussion
-59 -29 -9 -1 0 3 7 900