Computer Science Canada I need help with a selection sort |
Author: | Genisis [ Wed Jan 11, 2006 11:06 am ] | ||
Post subject: | I need help with a selection sort | ||
i dont know how to selection sort (5 numbers lowest to highest,with one array)i know how it works but i dont know how to type in code will someone help me out this is wat i got so far:
|
Author: | Tony [ Wed Jan 11, 2006 11:30 am ] |
Post subject: | |
Wikipedia has an example in C |
Author: | CooKieLord [ Mon Jan 23, 2006 5:52 pm ] |
Post subject: | |
Tony wrote: Wikipedia has an example in C
I'm sorry for posting on this "old" thread, but I need help with the sorting as well. I was reading through the example in C but I really don't understand. Can you help me out here? |
Author: | person [ Mon Jan 23, 2006 6:34 pm ] |
Post subject: | |
for example, u have 3 numbers that u want to sort and they are 2 3 1 1) check if 1<3=true? 2) 1<3 is true 3) check if 1<2=true? 4) 1<2 is true 5) 1 is now the first number in the sequence, and 2 is the last number in the sequence now the new sequence is: 1 3 2 6) check if 2<3=true? 7) 2<3 is true 8) 2 is now the second number in the sequence, and 3 is the last number in the sequence final result: 1 2 3 |
Author: | CooKieLord [ Mon Jan 23, 2006 6:47 pm ] | ||
Post subject: | |||
For steps 1 and 3, does it check the value or the array number (like number(x) )? I'm guessing array number. I've also discovered Bubble Sort, wich seems to fit my need. However I haven't decifered how it works yet.
Is it possible to explain the swapping process in another way? |
Author: | person [ Mon Jan 23, 2006 7:11 pm ] |
Post subject: | |
Bubble Sort: in a sequence of a,b,c,d. It only swaps with adjusent letters. e.g. c can only switch with b and d Selection Sort: in a sequence of a,b,c,d. It swaps the value of a letter with any letter, and it will never be checked again. e.g. a swaps with c, then a will never be checked again since it has acquired the correct value |
Author: | blaster009 [ Mon Jan 23, 2006 8:50 pm ] |
Post subject: | |
Alright...Now for a proper explanation in English. Bubble Sort: Why is it called Bubble Sort? An odd name for a computer pattern. Well, it is so named because Bubble Sort happens to resemble bubbles floating to the top of a pond. What Bubble sort does is it takes the largest number it can find, and continually moves it towards the end by swapping it with the number next to it. However, when bubble sort finds an even LARGER number, it will abandon the original one, and bring the new biggest number to the top, like so: 6,3,4,9,5,1 <---- Shift 3 and 6 3,6,4,9,5,1 <---- Shift 4 and 6 3,4,6,9,5,1 <---- Abandon 6, because 9 > 6. Shift 9 with 5 3,4,6,5,9,1 <---- Shift 9 with 1 3,4,6,5,1,9 <---- Now, we know that the highest number is at the top of the list, so we start all over again, and move numbers until we reach the second last position in the list, and so on, until we are only moving one number (which means the list is sorted). Someone else wanna take Selection? I'm a little short on time... |
Author: | person [ Tue Jan 24, 2006 5:17 pm ] |
Post subject: | |
since i have failed numerous times in trying to explain it, i will leave it to the internet to define it: http://www.nist.gov/dads/HTML/selectionsrt.html http://www.cs.ust.hk/faculty/tcpong/cs102/summer96/aids/select.html this is for selection sort (the second one has an animation) |
Author: | CooKieLord [ Fri Jan 27, 2006 9:51 am ] |
Post subject: | |
Oh I understand completely now, thanks alot for your efforts and explanations ![]() |