Jump to content
  • Advertisement
Sign in to follow this  
drjulio2002

Need help!

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone! Thanks:
do{
  flag=0;
   for(b=1;b<final-1;b++)
   {
    if(votes<=votes[b+1])
    {
	 stop = votes;
	 stops = pointers;
	 votes = votes[b+1];
	 pointers = 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
Advertisement

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!