Archive for February 12th, 2008

Tweets for 2008-02-12

  • Off to work – Listening to Buzz Out Loud – Hoping my head(cold?) doesn’t make my night too miserable. #
  • Looks like it’s gonna be a really long day – if it starts snowing. #
  • Really wish that the house wasn’t almost all running off of one 15 amp breaker. GAH! #
  • Up. Staring. Hungry, but not awake enough to realize it. #

Powered by Twitter Tools.

Bubble Sort again [C++]

 I’ve been busy doing the run around this week (AKA having a head cold), so I haven’t even had a chance to run this through the compiler yet… but elegiac and I have had a chance to step through the code again and see some blatant errors.

#include <iostream>
// namespace std; – I personally do not see the value in bringing the std into local.  So I’m not going to use it until I know better.

int sort[] = { [10, 2, 8, 4, 6, 0] };  // elegiac pointed out that arrays need curly braces, I like square.  So I combined them.
int i, x, y, z;
int elements;

int main() {
elements = sizeof(sort)/sizeof(sort[0]);  //  I think this will give me the number of elements within the array… I hope.
for (i=0; i < elements ; i++) {
if (sort[i] > sort[i+1]) { // Do I need to init (aka set to zero) my var holders for each cycle?
x=sort[i+1];
y=sort[i];
sort[i]=x;
sort[i+1]=y;
z=1; // Set if change is made
}
}
if (z) { // if change is made, run sorting cycle all over again
// I haven’t worked out the code for this one yet
}
for (i=0; i < elements ;i++) { // so this should go display the sorted information
std::cout << sort[i];
}
std::endl;
return = 0;
}