Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
completeBubbleSort
// // 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; }
run
|
edit
|
history
|
help
0
std::string(pid_t)
Even Odd using Functions
Raw AVL
Gauss 4x4
ThreadPool
Listas enlazadas - merge
Cuantos dedos
Peg Grammar AST Parser Computer Language Interpreter
Constructor.cpp
cppbasic