# Need help!

This topic is 5159 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everyone! Thanks:
do{
flag=0;
for(b=1;b<final-1;b++)
{
{
stops = pointers;
pointers = pointers[b+1];
pointers[b+1] = stops;
flag=1;
}
}
final = final - 1;
}while(flag==1);


[Edited by - drjulio2002 on September 1, 2004 6:44:27 PM]

##### Share on other sites

Note the cons, bubble sort is more of a learning experience than a useful sorting algorithm.

##### Share on other sites
for(a=1;a<final;a++){   for(b=a;b<final-1;b++)   {      if(votes<=votes[b+1])      {         stop = votes[a];	 stops = pointers[a];	 votes[a] = votes;	 pointers[a] = pointers;         votes = stop;	 pointers = stops;      }   }}

You were comparing 'a' with every 'b', you were comparing the first element with every other one, then the next first element with all the others, and so on, wrong. You need to compare 'b', with 'b+1', so that it compares with one element, and the next one, then advances, and compares again, one element with the next one.
Also 'a' starts with '1', i'm not sure that's a good thing.

1. 1
2. 2
3. 3
Rutin
21
4. 4
5. 5

• 15
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632927
• Total Posts
3009258
• ### Who's Online (See full list)

There are no registered users currently online

×