juggernot
Well-known member
- Joined
- Sep 28, 2006
- Messages
- 173
- Programming Experience
- Beginner
I was wondering if someone could show me how to do this. I attempted to do it already, but couldn't quite wrap my head around it If I had an array of random integers, lets say 100 integers, how would I sort them so that myarray(0) is the lowest, and the integers go in numerical order from there. My teacher was trying to show us how to do it, but is having problems himself. This was what he was trying to do:
For each integer in the array, compare myarray(0) to myarray(intcounter). If myarray(intcounter) < myarray(0), swap the values. This doesn't seem right to me, it seems ineffecient at best. I think it would work, but instead of swapping the values is there not just a way to insert a value at the top of an array, bumping all the other values? Any ideas?
For each integer in the array, compare myarray(0) to myarray(intcounter). If myarray(intcounter) < myarray(0), swap the values. This doesn't seem right to me, it seems ineffecient at best. I think it would work, but instead of swapping the values is there not just a way to insert a value at the top of an array, bumping all the other values? Any ideas?