Guest User

Untitled

a guest
Dec 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. // Stadistics of team
  2. typedef struct {
  3. tTeam* team;
  4. unsigned int num_Wins;
  5. unsigned int num_Draws;
  6. unsigned int points;
  7. double score;
  8. }tTeamStadistics;
  9.  
  10. // Definition of ranking of team
  11. typedef struct {
  12. tTeam* team;
  13. tTeamStadistics* stadistics;
  14. }tRanking;
  15.  
  16. // Definition of a list node
  17. typedef struct _tRankingListNode{
  18. tRanking e;
  19. struct _tRankingListNode* next;
  20. } tRankingListNode;
  21.  
  22. // Definition of a list of ranking
  23. typedef struct {
  24. tRankingListNode* first;
  25. } tRankingList;
  26.  
  27. // Create the ranking list
  28. void rankingList_createList(tRankingList* list){
  29. // PR3 EX2
  30.  
  31. list->first = NULL;
  32.  
  33. }
  34.  
  35. // Gets ranking node from given position
  36. tRankingListNode* rankingList_getNode(tRankingList* list, int index){
  37. // PR3 EX2
  38. tRankingListNode* tmp;
  39.  
  40. int i = 0;
  41. tmp=list->first;
  42.  
  43. while (i < index){
  44. tmp = tmp->next;
  45. i++;
  46. }
  47.  
  48. if (tmp == NULL){
  49. return NULL;
  50. }else{
  51. return tmp;
  52. }
  53. }
  54.  
  55. // Insert/adds a new ranking to the ranking list
  56. tError rankingList_insert(tRankingList* list, tRanking ranking, int index){
  57. tRankingListNode * tmp;
  58. tRankingListNode * prev;
  59.  
  60. tmp=(tRankingListNode*) malloc(sizeof(tRankingListNode));
  61.  
  62. if(tmp == NULL) {
  63. return ERR_MEMORY_ERROR;
  64.  
  65. }else{
  66. tmp->e=ranking;
  67. tmp->next=NULL;
  68. if(list->first==NULL){
  69. list->first=tmp;
  70. return OK;
  71. }else {
  72. prev = rankingList_getNode(list, index);
  73. if(prev != NULL){
  74. tmp->next=prev->next;
  75. prev->next=tmp;
  76. return OK;
  77. }else{
  78. return ERR_INVALID_INDEX;
  79. }
  80. }
  81. }
  82. }
Add Comment
Please, Sign In to add comment