Sign in to follow this  
drjulio2002

Need help!

Recommended Posts

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

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

Share this post


Link to post
Share on other sites

for(a=1;a<final;a++)
{
for(b=a;b<final-1;b++)
{
if(votes[b]<=votes[b+1])
{
stop = votes[a];
stops = pointers[a];
votes[a] = votes[b];
pointers[a] = pointers[b];
votes[b] = stop;
pointers[b] = 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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this