selection sort

The task is to get 6 test scores, find the lowest score and drop it , and then average the remaining 5.



Would it be possible to implement a selection sort on an array of variables and drop the lowest value? I was thinking it wouldn't be that difficult since after they are sorted the lowest value should be in the first index, but i am not quite sure how i would drop the first index from the array.
There's a simpler algorithm that only requires a single pass through the array.
You can just skip over that element altogether. Depending on how you sort it, it'll be in the front or end of the array, so just either start at 1 or end at size-2 (i < size-1)
I think the point is that you don't need to sort at all.
When you're reading them in, sum them all up but also determine the lowest.
After you've read them in, subtract the lowest from the sum.
Determine the average from that.
okay thanks so much.. The selection sort is not required for my project but we get extra points if we use it so i was just wondering.
Funny, I had to code selection sort in assembly just for regular points. Not using it meant getting a 0 on the assignment. Good times.
extra points for doing something inefficiently. Sigh.
sort it, and then ignore the [0] element, average from [1] to [n].
arrays have a fixed size. if the array is size[6] its always size[6].
you can copy 1...5 into a [5] sized copy of the array, if you want to do that, or you can hard-code it to ignore the [0]th element. Both work.
Last edited on
Topic archived. No new replies allowed.