public class Selection{
static void switcharound(float[] s, int i, int j){
float m = s[i];
float n = s[j];
s[i] = n;
s[j] = m;
// switch the values of s[i] and s[m] around
}
static void switchMin(float[] t, int index){
// inner loop. places a single index
double minValue = 100000000;
int minIndex = 0;
for( int i = index; i < t.length; i++ ){
if( minValue >= t[i] ){
minValue = t[i];
// decrease minValue until it reaches the minimum value
minIndex = i;
// set minIndex to the index with the minimum value
}
}
switcharound(t, index, minIndex);
}
static void sort(float[] t){
// outer loop. places each index
for( int i = 0; i < t.length; i++ ){
switchMin(t, i);
}
}
}
That took me something like five hours to write. Five hours of coding and debugging, for three modules and 29 lines of code. Imagine what's going to happen when I start writing application programs that are 500 lines long. I'll need to find a better way to predict what is going to happen with code before I write it, so I don't end up messing up so much. Is there anything I can do to make my coding habits less sloppy? Maybe the GNU Debugger or something along those lines? Or is this something that will come with skill?


Sign In
Create Account


Back to top









