![]() |
Sorting bug
Hi. At College we've been asked to make an application in C that sort a card game. No big deal, but have made a sorting function that sorting strangely...
It's a Bubblesort. Can you help me to fix it? Here's the code, sorry, but the name of variables are in french. I put in bold the bugging Bubblesort function. Thanks a lot. :
#include <conio.h> |
I would observe thusly: If I had a card whose color or value put it out of sort, I would sort the card. I would not scrape off the number or the symbol and paste it on another card.
|
Thanks, but I don't really understand what you mean.....
|
I removed everything except what was needed to show you how to sort -
:
#include <stdlib.h> |
Thanks, but i paste it on a blank file and it bug on this line :
:
qsort(jeu,num,sizeof(struct Carte),compar);Borland give me a huge error of missmatch of parameters.... Thanks! |
Forget about it, a classmate had found the solution.
:
void triJeu(struct Carte jeu [])See ya next time. |
You could remove your second loop if you change your test in the first loop from
:
if(jeu[j].couleur < jeu[j-1].couleur):
if((jeu[j].couleur *100 + jeu[j].valeur) < (jeu[j-1].couleur * 100 + jeu[j-1].valeur))This makes the first loop work out what order the cards should go in by suit and value. The "* 100" weighting for the couleur is pretty arbitrary, it could be any value above 14. |
qsort is supported by Borland compilers....
|
Quote:
|
well, it would probably not be allowed for the assignment.
|
| All times are GMT -5. The time now is 5:08 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC