Has everyone finished assignment 3? It seems that no one is having any problem as there are no posts on it. Can anyone tell me how to appraoch question 4 on bublesort. any tip will be much appreciated.Goodluck.
Last year one of my prescribed books were "Foundations of Computer Science" by Forouzan (Can't remember the COS code) In it is a very good description of bubble sort, I used the explanation in that book and developed my algorithm from there, It worked first time. (But me and meansort...we no family).
Bubble Sort, mmmm... that was fun. It's pretty straight forward, so i'm gonna post my way of doing it for those who can't snap it (not giving code cause that'll take the fun out of figuring it out and understanding it).
For those for you that are completely at a loss, think like this, it's called a bubble sort cause essentially the element bubble up into order.
what you need to keep in mind is that if your list has n unsorted elements then you'll need to pass thru your list n*n times (so 10 elements will give you 100 passes). I used 2 loop, the inner compares two adjacent elements and swapping as necessary. the outer loop just resets my index so that the inner can start from the end again and ensures that all the elements are check.
so, for a list of 10 elements you are gonna loop a "countdown" from the last to the first element and inside that loop the comparing and swapping the elements.
i reckon that for an extra fun try making it recursive...