thanks for the replay but what i am having trouble is that I can't use square brackets any where in the program, for instance list[]. I have to write it like this *(list+i), like i did above in the code. so how would i go about doing the bubble sort. If someone could give me an example that would help.
It it a horrible restriction for the program i have to write. That is the reason I am having trouble. So if anyone could give me an example from the code i have provided that will help me greatly.
hanst99
Yes, but if he isn't required to implement bubble sort it wouldn't hurt doing it better, now would it?
If you're two or three lines away from successfully implementing a bubble sort, I'd have said the best thing would be to fix that first, then move onto something more advanced.
keineahnugh thanks for the replay. I know that *(list+i) is same as list[i]. But in the sort function how would i add x variable that i did for the loop. Also I can't use bool because i am writing this program in C.
Thanks for the reply keineahnung. would the sort function look something like this
Hi
For bool just substitute an int. If it's 0 it's false, anything else is true. That's all an 'if' statement checks for.
Your function header's now wrong - before it was correct: void sort( int* list, int count )
All you've got to do is copy that function I linked to, swap bool for int and then make some slight alterations to the pointer stuff.
I'd suggest you copy and paste it into your program and get it working first, then make the alterations, one line at a time, re-compile and confirm it still works between each change.
So for example, this line: if (arr[i] > arr[i + 1]) {
is going to become: if ( *(arr + i) >
etc.
Note in that function that you don't just loop through the list once. That's not how bubble sort works. You need to go through it over and over again until the lower values (or upper, depending on how you're sorting) 'bubble' up to the top. That's why the for loop's enclosed within a while loop. The answer's all in that link.
Can't really say much else without writing it for you ;)