Guest User

Untitled

a guest
Apr 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1.     // Add all runs to its corresponding runner
  2.     RUN *currentRunPos = head;
  3.     while (currentRunPos != NULL) {
  4.         int runnerFound = 0; // assume that the runner has not been found
  5.         RUNNER *currentRunnerPos = headRunner;
  6.         while (currentRunnerPos != NULL) {
  7.             if (strcmp(currentRunPos->name,currentRunnerPos->name) == 0) {
  8.                 currentRunnerPos->distance += currentRunPos->distance;
  9.                 currentRunnerPos->duration += currentRunPos->duration;
  10.                 runnerFound = 1;
  11.                 break; // quit the while loop as the runner has been found
  12.             }
  13.             currentRunnerPos = currentRunnerPos->next;
  14.         }
  15.         // Create a new runner if the runner was not found and set his data
  16.         if (!runnerFound) {
  17.             RUNNER *newRunner = malloc(sizeof(RUNNER));
  18.             newRunner->distance = currentRunPos->distance;
  19.             newRunner->duration = currentRunPos->duration;
  20.             strcpy(newRunner->name, currentRunPos->name);
  21.             newRunner->next = headRunner;
  22.             headRunner = newRunner;
  23.         }
  24.         currentRunPos=currentRunPos->next;
  25.     }
Add Comment
Please, Sign In to add comment