Archive for February 16th, 2008

Tweets for 2008-02-16

  • Success! I have the TV Center from store number 6. And ATT finally gave me the family TXT plan I wanted. #
  • Getting ready to head out. Would rather stay home. #
  • The best part of the weekend: nap time. #

Bubble Sort in flux [C++]

I’ve started to hack into my marginally functional program … and I’m starting to think I’ve probably messed it up to the point of needing to start over from a clear slate. It doesn’t help that I haven’t bothered to look up the proper way to structure a “do…while”.

#include <iostream>

int sort[] = { 2, 3, 1, 5, 4, 6 }; // Curly braces – NOT brackets.
int i = 0;
int x = 0;
int y = 0;
int z = 0;
int elements;

int main() {
elements = sizeof(sort)/sizeof(sort[0]); // How many elements are we sorting?
do {
// I haven’t worked out the code for this one yet
if (sort[i] > sort[i+1]) {
x=sort[i+1];
y=sort[i];
sort[i]=x;
sort[i+1]=y;
z=0; // Set if change is made
}
else { z = 1; }
if (i < elements) { i++; }
} while (z = 0);
for (i=0; i < elements ;i++) { // so this should go display the sorted information
std::cout << sort[i];
}
return 0;
}