Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.09 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. //structura pentru jucator
  6. typedef struct Player
  7. {
  8. char *last_name;
  9. char *first_name;
  10. int score;
  11. } Player;
  12.  
  13. //structura pentru tara
  14. typedef struct Country
  15. {
  16. char *name;
  17. int nr_players;
  18. int global_score;
  19. Player *players;
  20. struct Country* next;
  21. struct Country* prev;
  22. } Country;
  23.  
  24. typedef struct Queue
  25. {
  26. Country *front;
  27. Country *rear;
  28. } Q;
  29.  
  30. typedef struct root
  31. {
  32. Player* jucator;
  33. struct root *left;
  34. struct root *right;
  35. } root;
  36.  
  37. typedef struct stackTree// structura pentru nod din stiva
  38. {
  39. root *treeNode;
  40. struct stackTree *next;
  41. } stackTree;
  42.  
  43. //structura pentru stiva
  44. /*typedef struct stackNode
  45. {
  46. Country countryElem;
  47. struct stackNode *next;
  48. }stackNode;
  49. */
  50. /*typedef struct nodeCountry
  51. {
  52. Country country;
  53. struct nodeCountry* next;
  54. struct nodeCountry* prev;
  55. } NC;*/
  56.  
  57. void add(Country *head, FILE** f); //functie de adaugare nod
  58. void FiletoList(Country **head, int* noCountries); // functie de deschidere fisier + aflarea numarului de tari + facut nodurile cu add
  59. double countryAverage(Country *head); // pentru a afla media scorurilor jucatorilor
  60. double findMinimum(Country *head); // functie de gasit media aritmetica cea mai mica
  61. void removeCountry(Country *head, int *noCountries); // functie de eliminat o tara din lista
  62. char* cerinte(); // functie pentru citirea cerintelor
  63. void printList(Country *head); // functie pentru afisarea elementelor din lista
  64. int bitCount(int n); // functie de calculat numarul de biti in binary al unui numar, necesar pentru a vedea daca un numar este putere a lui 2.
  65. void push(Country **top, Country added); // functia de adaugat elemente in varful stivei
  66. int isEmpty(Country *top); // functie ce verifica daca e plina/goala stiva
  67. Country* ListToStack(Country* head, Country** top); // functie ce imi pune elementele din lista in stiva
  68. void printStack(Country *top, int noCountries); // functie de afisare a stivei
  69. void deleteList(Country **head); // functie pentru stergerea listei inlantuite
  70. Q *createQueue(); // functie ce imi creeaza o coada
  71. void enQueue(Q *q, Country country); // functie ce imi adauga element in coada
  72. void playGames(Country **top,Q *queue, Country **winnerStack, int *noCountries); // functia ce baga elementele din stiva initiala in coada, face meciurile, le baga in stiva winner
  73. void winnertoTree(Country **winnerStack, root **node, int noCountries);
  74. void delTop(Country **top, int *remCountries); // functie de eliminat top-ul stack-ului
  75. void delTopnoCountries(Country** top, int remCountries); // functie ce elimina top-ul stack-ului, fara a modifica numarul de tari
  76. void allGames(Country *top,Q* queue,Country **winnerStack,int *noCountries,root** node); //functie in care sunt calculate outcome-urile tuturor meciurilor
  77. void printWinner (Country *winnerStack,int noCountries); // afisarea echipelor castigatoare
  78. void reverseStack(Country **top, int noCountries);
  79. void winnertoInit(Country **initTop,Country **winnerTop, int noCountries); // functie ce imi pune elementele din stiva winner in stiva initiala
  80. FILE *openAppend(); // functie pentru deschiderea unui fisier cu rol de append
  81. FILE *openWrite(); // functie pentru deschiderea unui fisier cu rol de write
  82. root* minValue(root* node); // functie de aflarea valorii minime dintr-un BST
  83. root* deleteNode(root* node,Player *toDelete); // functie ce sterge un nod din BST
  84. root* InsertNode(root* node,Player *toAdd); // functie ce adauga un element in BST
  85. root* changeScores(root* node,Player *toChange); // functie ce imi actualizeaza valorile din BST
  86. void printClasament(root * node); // functie pentru afisarea clasamentului (cerinta 4)
  87. void printDecOrder(root *node, FILE *fout);
  88. void BTtoBST(root* node,root** newBST);
  89. void deleteBT(root *node);
  90.  
  91. int main()
  92. {
  93. FILE *input, *output;
  94. Country *head=NULL, *stackTop=NULL, *winnerStack=NULL;
  95. Q *q;
  96. root* BST = NULL;
  97. int noCountries;
  98. char *tasks=cerinte();
  99. FiletoList(&head,&noCountries);
  100. removeCountry(head,&noCountries);
  101. printList(head);
  102. stackTop = ListToStack(head,&stackTop);
  103. stackTop->prev->next = NULL;
  104. allGames(stackTop,q,&winnerStack,&noCountries,&BST);
  105. printClasament(BST);
  106. printf("%d",noCountries);
  107. return 0;
  108. }
  109.  
  110.  
  111. void printList(Country* head)
  112. {
  113. FILE *fout = openWrite();
  114. Country *travel=head->next;
  115. int i;
  116. while(travel != head)
  117. {
  118. fprintf(fout,"%s\n",travel->name);
  119. travel = travel->next;
  120. }
  121. fclose(fout);
  122.  
  123. }
  124.  
  125. void printStack(Country *top, int noCountries)
  126. {
  127. Country *traveler = top;
  128. int i,j;
  129. for (i=0 ; i<noCountries; i++)
  130. {
  131. printf("%s\n",traveler->name);
  132. traveler = traveler->next;
  133. }
  134.  
  135. }
  136.  
  137. char* cerinte() // functie pentru citirea cerintelor
  138. {
  139. FILE *fcerinte;
  140. int i;
  141. char *c = (char*)malloc(5* sizeof(char)); // 5*sizeof(char) pentru ca sunt 5 cerinte
  142. if((fcerinte=fopen("cerinte.in","r"))==NULL)
  143. {
  144. printf("Eroare la deschiderea cerinte.in pentru citire");
  145. exit(55);
  146. }
  147.  
  148. for(i=0; i<5; i++)
  149. fscanf(fcerinte,"%c %[ ]",&c[i]);
  150. fclose(fcerinte);
  151. return c;
  152. }
  153.  
  154. void add(Country *head, FILE** f) //functie de adaugare nod
  155. {
  156. Country *newNode, *tail=head->next;
  157. char str[BUFSIZ];
  158.  
  159. newNode=(Country*)malloc(sizeof(Country)); //creez un nou nod
  160. fscanf(*f,"%d %s",&newNode->nr_players, str); // citesc din fisier numarul de jucatori si numele tarii(stochez numele tarii intr-un auxiliar)
  161. newNode->name=malloc(strlen(str)+1); //alocare pentru numele tarii
  162. strcpy(newNode->name,str);
  163. newNode->global_score=0; //by default, scorul global initial este 0;
  164. newNode->players=malloc(sizeof(Player)*newNode->nr_players);
  165. for(int i=0 ; i<newNode->nr_players ; i++)
  166. {
  167. fscanf(*f,"%s",str); //citesc numele de familie la fel cum am facut cu numele tarii
  168. newNode->players[i].last_name=malloc(strlen(str)+1);
  169. strcpy(newNode->players[i].last_name,str);
  170.  
  171. fscanf(*f,"%s",str); // procedez la fel si pentru prenume
  172. newNode->players[i].first_name=malloc(strlen(str)+1);
  173. strcpy(newNode->players[i].first_name,str);
  174.  
  175. fscanf(*f, "%d", &newNode->players[i].score); //scorul jucatorului
  176. }
  177. while(tail->next != head)
  178. tail=tail->next; //ma deplasez spre 'finalul' listei
  179.  
  180. //adaug noul nod la final si fac legaturile next/prev corespunzatoare
  181. tail->next=newNode;
  182. newNode->next=head;
  183. newNode->prev=tail;
  184. head->prev=newNode;
  185. }
  186.  
  187.  
  188. void FiletoList(Country **head, int* noCountries) // functie de deschidere fisier + aflarea numarului de tari + facut nodurile cu add
  189. {
  190. FILE *finput;
  191. if((finput=fopen("date.in","r"))==NULL)
  192. {
  193. printf("Eroare la deschiderea date.in pentru citire");
  194. exit(55);
  195. }
  196. fscanf(finput,"%d",noCountries);
  197.  
  198. (*head)=(Country*)malloc(sizeof(Country));
  199. (*head)->next=(*head); //lista circulara dublu inlantuita
  200. (*head)->prev=(*head);
  201.  
  202. for(int i=0; i<(*noCountries); i++) // stim numarul de tari, deci stim cate noduri avem de creat cu add
  203. add(*head,&finput);
  204. fclose(finput);
  205. }
  206.  
  207. double countryAverage(Country *head) // media scorurilor jucatorilor unei tari
  208. {
  209. double mean=0;
  210. Country* traveler=head;
  211. for(int i=0 ; i<traveler->nr_players; i++)
  212. {
  213. mean+=traveler->players[i].score;
  214. }
  215. mean=mean/traveler->nr_players;
  216. return mean;
  217. }
  218.  
  219. double findMinimum(Country *head) // functie de gasit media aritmetica cea mai mica
  220. {
  221. double minimum=0;
  222. Country *headcopy=head->next;
  223. minimum=countryAverage(headcopy);
  224. headcopy=headcopy->next;
  225. while(headcopy!=head)
  226. {
  227. if(countryAverage(headcopy)<minimum)
  228. minimum=countryAverage(headcopy);
  229. headcopy=headcopy->next;
  230. }
  231. return minimum;
  232. }
  233.  
  234. void removeCountry(Country *head, int *noCountries) // functie de eliminat o tara
  235. {
  236. Country *traveler= head->next, *temp;
  237.  
  238.  
  239. while( bitCount(*noCountries)!=1 ) // verific daca numarul de tari e o puterea a lui 2
  240. {
  241. traveler=head->next;
  242. while(traveler!=head)
  243. {
  244. if(countryAverage(traveler)==findMinimum(head))
  245. {
  246. temp=traveler;
  247. if(traveler->next != head)
  248. (traveler->next)->prev=traveler->prev;
  249. else
  250. {
  251. (traveler->prev)->next=head;
  252. head->prev=traveler->prev;
  253. }
  254. if(traveler->prev!= head)
  255. (traveler->prev)->next=traveler->next;
  256. else
  257. {
  258. (traveler->next)->prev=head;
  259. head->next=traveler->next;
  260. }
  261. (*noCountries)--; // de fiecare data cand elimin o tara decrementez numarul de tari existente
  262.  
  263. free(temp);
  264. break;
  265. }
  266.  
  267. traveler=traveler->next;
  268. }
  269. }
  270. }
  271. int bitCount(int n) // functie pentru a verifica daca un numar e putere a lui 2. Un numar e putere a lui 2 daca in binary este format dintr-un singur bit 1
  272. {
  273. int count=0;
  274. while(n>0)
  275. {
  276. if(n & 1)
  277. ++count;
  278. n >>=1;
  279. }
  280. return count;
  281. }
  282.  
  283. void push(Country **top,Country added) // functie de adaugat un element in varful stivei
  284. {
  285. Country *newNode = (Country*)malloc(sizeof(Country));
  286. (*newNode) = added;
  287. newNode->next = (*top);
  288. (*top) = newNode;
  289.  
  290. }
  291.  
  292. int isEmpty(Country *top) // functie ce verifica daca e plina/goala stiva
  293. {
  294. return top==NULL;
  295. }
  296.  
  297. int isEmptyQueue(Q* queue)
  298. {
  299. return(queue->front == NULL);
  300. }
  301.  
  302. void delTop(Country** top, int *remCountries) // functie de sters elementul din varful stivei, modific si numarul tarilor. ex: cand pun tarile din stiva initiala in stiva winners
  303. {
  304. if(*remCountries == 0)
  305. (*top) = NULL;
  306. else
  307. {
  308. Country *temp = (*top);
  309. Country *aux = temp->next;
  310.  
  311. if(aux != NULL)
  312. (*top) = (*top)->next;
  313. else
  314. (*top) = NULL;
  315.  
  316. free(temp);
  317. (*remCountries)--;
  318. }
  319.  
  320. }
  321. void delTopnoCountries(Country** top, int remCountries) // functie de sters elementul din varful stivei. nu modific numarul de tari (ex: cand pun tarile din winners in stiva initiala)
  322. {
  323. if(remCountries == 0)
  324. (*top) = NULL;
  325. else
  326. {
  327. Country *temp = (*top);
  328. Country *aux = temp->next;
  329.  
  330. if(aux != NULL)
  331. (*top) = (*top)->next;
  332. else
  333. (*top) = NULL;
  334.  
  335. free(temp);
  336. }
  337.  
  338. }
  339.  
  340. Country* ListToStack(Country* head, Country** top) // functie de pus elementele din lista in stiva
  341. {
  342. Country *traveler = head->next;
  343. while(traveler != head)
  344. {
  345. push(top,(*traveler));
  346. traveler = traveler->next;
  347. }
  348. //traveler->next = NULL;
  349. //push(top, (*traveler));
  350. //deleteList(&head);
  351. return (*top);
  352. }
  353.  
  354. void deleteList(Country **head) //functie de stergere a listei
  355. {
  356. Country *temp = (*head)->next, *aux = temp;
  357. while(temp != (*head))
  358. {
  359. temp = temp->next;
  360. free(aux);
  361. aux = temp;
  362. }
  363. free(head);
  364. }
  365.  
  366. Q *createQueue() // functie ce imi creeaza o coada
  367. {
  368. Q *q;
  369. q = (Q*)malloc(sizeof(Q));
  370. if(q==NULL)
  371. return NULL;
  372.  
  373. q->front = q->rear = NULL;
  374. return q;
  375. }
  376.  
  377. void enQueue(Q *q, Country country) // functie ce imi adauga element in coada
  378. {
  379. Country *newNode = (Country*)malloc(sizeof(Country));
  380. *newNode = country;
  381. newNode->next = NULL;
  382.  
  383. //adaugam noul nod la finalul cozii
  384. if(q->rear==NULL) // daca nu avem niciun nod in coada
  385. q->rear = newNode;
  386. else
  387. {
  388. (q->rear)->next = newNode;
  389. q->rear= newNode;
  390. }
  391. if (q->front == NULL)
  392. q->front = q->rear; // daca e singurul element din coada
  393. }
  394.  
  395. void deleteQueue(Q *queue) // functie ce sterge o coada
  396. {
  397. Country *aux;
  398. while (!isEmptyQueue(queue))
  399. {
  400. aux = queue->front;
  401. queue->front = queue->front->next;
  402. free(aux);
  403. }
  404. queue->rear = NULL;;
  405. }
  406.  
  407. void playGames(Country **top,Q *queue, Country **winnerStack,int *noCountries) // in aceasta functie pun elementele din stiva initiala in coada de meciuri, le pun in stiva winner
  408. {
  409.  
  410. int i,j,initialCountries=(*noCountries);
  411. int firstLocal=0, secondLocal=0; // variabile pentru scorurile locale ale celor doua tari
  412. Country *firstCountry, *secondCountry;
  413. firstCountry=malloc(sizeof(Country));
  414. secondCountry=malloc(sizeof(Country));
  415. //queue = createQueue();
  416.  
  417. while(!isEmpty(*top)) // cat timp exista elemente in stiva initiala, iau primele doua tari si le pun in coada
  418. {
  419. FILE *fout = openAppend();
  420. queue = createQueue();
  421. (*firstCountry)=(**top);
  422. delTop(&(*top),&initialCountries);
  423. (*secondCountry)=(**top);
  424. delTop(&(*top),&initialCountries);
  425. enQueue(queue,(*firstCountry));
  426. enQueue(queue,(*secondCountry));
  427.  
  428. fprintf(fout,"\n%s %d ----- %s %d",queue->front->name,queue->front->global_score,queue->rear->name,queue->rear->global_score);
  429.  
  430. for(i=0 ; i<queue->front->nr_players ; i++)
  431. {
  432. for(j=0 ; j<queue->rear->nr_players ; j++)
  433. {
  434. fprintf(fout,"\n%s %s %d vs %s %s %d",queue->front->players[i].last_name,queue->front->players[i].first_name,queue->front->players[i].score,queue->rear->players[j].last_name,queue->rear->players[j].first_name,queue->rear->players[j].score);
  435. if(queue->front->players[i].score == queue->rear->players[j].score) // daca este egalitate intre cei doi jucatori
  436. {
  437. queue->front->players[i].score += 2;
  438. queue->rear->players[j].score += 2;
  439. firstLocal++;
  440. secondLocal++;
  441. }
  442. else if (queue->front->players[i].score < queue->rear->players[j].score) // daca al doilea jucator castiga
  443. {
  444. queue->rear->players[j].score += 5;
  445. secondLocal += 3;
  446. }
  447. else // daca primul jucator castiga
  448. {
  449. queue->front->players[i].score += 5;
  450. firstLocal += 3;
  451. }
  452.  
  453. }
  454. }
  455. fprintf(fout,"\n");
  456.  
  457. queue->front->global_score += firstLocal; // dupa terminarea meciurilor adaugam scorul local final la cel global
  458. queue->rear->global_score += secondLocal;
  459.  
  460.  
  461.  
  462. if(firstLocal>=secondLocal) // adaugam in stiva Winner tara cu punctajul local mai mare
  463. push(&(*winnerStack),*(queue->front));
  464. else
  465. push(&(*winnerStack),*(queue->rear));
  466.  
  467.  
  468.  
  469.  
  470. deleteQueue(queue); // meciurile s-au terminat, nu mai avem nevoie de coada
  471. firstLocal = 0;
  472. secondLocal = 0;
  473. fclose(fout);
  474. }
  475.  
  476. (*noCountries) /= 2; // dupa ce se termina toate meciurile dintr-o etapa numarul de tari se va injumatati
  477. }
  478.  
  479. void winnertoTree(Country **winnerStack, root **node, int noCountries)
  480. {
  481. root* newBST = NULL;
  482.  
  483. if(noCountries == 4 ) // daca sunt ultimele 4 tari ramase trebuie doar introduse in BST
  484. {
  485. Country *temp = *winnerStack;
  486. while(temp != NULL)
  487. {
  488. int i;
  489. for(i=0 ; i<temp->nr_players; i++)
  490. {
  491. *node = InsertNode(*node,&temp->players[i]);
  492. }
  493. temp = temp->next;
  494. }
  495. }
  496. if(noCountries == 1) // la ultima tara ramasa, BST-ul initial devine BT, intrucat scorurile se modifica
  497. {
  498. BTtoBST(*node,&newBST);
  499. deleteBT(*node);
  500. *node = newBST;
  501. }
  502. }
  503.  
  504. void BTtoBST(root* node, root** newBST)
  505. {
  506. if(node == NULL)
  507. return;
  508. BTtoBST(node->left,newBST);
  509. (*newBST) = InsertNode(*newBST,node->jucator);
  510. BTtoBST(node->right,newBST);
  511. }
  512.  
  513.  
  514. void deleteBT(root *node) // stergerea arborelui, intrucat 'schimb' arborele
  515. {
  516. if(!node)
  517. return;
  518. deleteBT(node->left);
  519. deleteBT(node->right);
  520. free(node);
  521. }
  522.  
  523. void allGames(Country *top,Q *queue, Country **winnerStack,int *noCountries, root **node)
  524. {
  525.  
  526. int i=1;
  527. while((*noCountries)>1)
  528. {
  529. FILE *fout = openAppend();
  530. fprintf(fout,"\n===== ETAPA %d =====\n",i);
  531. fclose(fout);
  532. playGames(&top,queue,winnerStack,noCountries);
  533. printWinner(*winnerStack,(*noCountries));
  534. winnertoTree(winnerStack, node, *noCountries);
  535. winnertoInit(&top,winnerStack,(*noCountries));
  536. i++;
  537. }
  538. }
  539.  
  540. void printWinner (Country *winnerStack,int noCountries) // functie ce printeaza stiva winner
  541. {
  542. FILE *fout = openAppend();
  543. Country *traveler = winnerStack;
  544. int i;
  545. fprintf(fout,"\n=== WINNER ===\n");
  546. for (i=0 ; i<noCountries; i++)
  547. {
  548. fprintf(fout,"%s --- %d\n",traveler->name,traveler->global_score);
  549. traveler = traveler->next;
  550. }
  551. fclose(fout);
  552. }
  553.  
  554. void winnertoInit(Country **initTop,Country **winnerTop, int noCountries)
  555. {
  556. while(!isEmpty(*winnerTop))
  557. {
  558. push(&(*initTop),*(*winnerTop));
  559. delTopnoCountries(winnerTop,noCountries);
  560. }
  561.  
  562. }
  563.  
  564. FILE *openWrite() // functie pentru deschiderea unui fisier cu rol de write
  565. {
  566. FILE *fout;
  567. if((fout = fopen("rezultate.out","w")) == NULL)
  568. {
  569. fprintf(fout,"eroare la deschiderea rezultate.out pentru scriere");
  570. exit(-55);
  571. }
  572. return fout;
  573. }
  574.  
  575. FILE *openAppend() // functie pentru deschiderea unui fisier cu rol de append
  576. {
  577. FILE *fout;
  578. if((fout = fopen("rezultate.out","a")) == NULL)
  579. {
  580. fprintf(fout,"eroare la deschiderea rezultate.out pentru append");
  581. exit(-55);
  582. }
  583. return fout;
  584. }
  585.  
  586. root* newNode (Player *toAdd) // functie ce imi creeaza un nou nod
  587. {
  588. root *node = (root*)malloc(sizeof(root));
  589. node->jucator = toAdd;
  590. node->left = node->right = NULL;
  591. return node;
  592. }
  593.  
  594. root* InsertNode(root* node,Player *toAdd) // functie ce insereaza un nou nod in BST
  595. {
  596. if ( node == NULL )
  597. return newNode(toAdd);
  598. if(toAdd->score == node->jucator->score) // cazul in care au acelasi scor
  599. {
  600. if(strcmp(toAdd->last_name,node->jucator->last_name)<0) // daca cel pe care il adaugam are numele mai mic dpdv lexicografic
  601. {
  602. node->jucator = toAdd;
  603. }
  604. else if(!strcmp(toAdd->last_name,node->jucator->last_name)) // daca au acelasi nume dpdv lexicografic
  605. {
  606. if(strcmp(toAdd->first_name,node->jucator->first_name)<0) // comparam prenumele si il adaugam daca are numele mai mic decat nodul deja prezent, altfel in lasam asa
  607. node->jucator = toAdd;
  608. else
  609. return node;
  610. }
  611. else
  612. return node;
  613.  
  614. }
  615.  
  616. else if(toAdd->score < node->jucator->score)
  617. node->left = InsertNode(node->left, toAdd);
  618. else if(toAdd->score > node->jucator->score)
  619. node->right = InsertNode(node->right,toAdd);
  620. return node;
  621. }
  622.  
  623. root* minValue(root* node) // functie ce cauta minimul dintr-ul BST
  624. {
  625. root* traveler = node;
  626. while(traveler->left != NULL)
  627. traveler = traveler->left;
  628. return traveler;
  629. }
  630.  
  631. root* deleteNode(root* node,Player *toDelete) // functie ce sterge un nod din BST
  632. {
  633. if(node == NULL)
  634. return node;
  635. if(!strcmp(node->jucator->first_name,toDelete->first_name) && !strcmp(node->jucator->last_name,toDelete->last_name)) // daca a gasit jucatorul de sters (acelasi nume)
  636. {
  637. if(node->left == NULL) // daca e un singur copil
  638. {
  639. root* temp = node->right;
  640. free(node);
  641. return temp;
  642. }
  643. else if (node->right == NULL)
  644. {
  645. root *temp = node->left;
  646. free(node);
  647. return temp;
  648. }
  649. root *temp = minValue(node->right); // daca are 2 copii, gasim minimul din subarborele drept pentru a schimba pozitiile
  650. node->jucator = temp->jucator;
  651. node->right = deleteNode(node->right,temp->jucator);
  652. }
  653. node->left = deleteNode(node->left,toDelete);
  654. node->right = deleteNode(node->right,toDelete);
  655. return node;
  656. }
  657.  
  658. root* changeScores(root* node,Player *toChange) // Functie ce actualizeaza BST-ul dupa scorul jucatorilor si reface legaturile corespunzatoare
  659. {
  660. node = deleteNode(node,toChange);
  661. node = InsertNode(node,toChange);
  662. return node;
  663. }
  664.  
  665. void printDecOrder(root* node, FILE* fout) // daca parcurgem DRS arborele, vom obtine elementele in ordine descrescatoare
  666. {
  667. if (node == NULL)
  668. return;
  669. printDecOrder(node->right,fout);
  670. fprintf(fout,"%s %s %d\n",node->jucator->last_name,node->jucator->first_name,node->jucator->score);
  671. printDecOrder(node->left,fout);
  672. }
  673.  
  674. void printClasament(root * node) // functie pentru afisarea clasamentului (cerinta 4)
  675. {
  676. FILE *fout = openAppend();
  677. fprintf(fout,"\n====== CLASAMENT JUCATORI ======\n");
  678. printDecOrder(node,fout);
  679. fclose(fout);
  680. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement