Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Stadistics of team
- typedef struct {
- tTeam* team;
- unsigned int num_Wins;
- unsigned int num_Draws;
- unsigned int points;
- double score;
- }tTeamStadistics;
- // Definition of ranking of team
- typedef struct {
- tTeam* team;
- tTeamStadistics* stadistics;
- }tRanking;
- // Definition of a list node
- typedef struct _tRankingListNode{
- tRanking e;
- struct _tRankingListNode* next;
- } tRankingListNode;
- // Definition of a list of ranking
- typedef struct {
- tRankingListNode* first;
- } tRankingList;
- // Create the ranking list
- void rankingList_createList(tRankingList* list){
- // PR3 EX2
- list->first = NULL;
- }
- // Gets ranking node from given position
- tRankingListNode* rankingList_getNode(tRankingList* list, int index){
- // PR3 EX2
- tRankingListNode* tmp;
- int i = 0;
- tmp=list->first;
- while (i < index){
- tmp = tmp->next;
- i++;
- }
- if (tmp == NULL){
- return NULL;
- }else{
- return tmp;
- }
- }
- // Insert/adds a new ranking to the ranking list
- tError rankingList_insert(tRankingList* list, tRanking ranking, int index){
- tRankingListNode * tmp;
- tRankingListNode * prev;
- tmp=(tRankingListNode*) malloc(sizeof(tRankingListNode));
- if(tmp == NULL) {
- return ERR_MEMORY_ERROR;
- }else{
- tmp->e=ranking;
- tmp->next=NULL;
- if(list->first==NULL){
- list->first=tmp;
- return OK;
- }else {
- prev = rankingList_getNode(list, index);
- if(prev != NULL){
- tmp->next=prev->next;
- prev->next=tmp;
- return OK;
- }else{
- return ERR_INVALID_INDEX;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment