| Author |
problem in simple bubble sort logic..
|
Punit Jain
Ranch Hand
Joined: Aug 20, 2011
Posts: 908
|
|
hello i m just trying to do searching and sortings at my own.
i don't know but i am doing something wrong in my bubble sort code.
can anyone help me in this, below is my code:
there is something wrong in my sort function.
my data is not getting sort.
i also search on google, i found lots off code there, but i want to know what i am doing wrong..
Thank you...
|
 |
Anand Hariharan
Rancher
Joined: Aug 22, 2006
Posts: 252
|
|
I haven't looked at it in great detail, but usually, when I see <= as the condition in a for loop, methinks it is wrong. For example, it appears that your inner (i.e., j index for loop) when i = n-1 and j=i will access array out of bounds.
Some other points to consider:
Terminate your printf string literals with \n (new line) characterAlways check scanf's return value.Try to avoid I/O altogether (nothing wrong in hard-coding your inputs within your source when you are simply trying to learn sort algorithms).
best wishes,
- Anand
|
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
|
 |
 |
|
|
subject: problem in simple bubble sort logic..
|
|
|