Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Add all runs to its corresponding runner
- RUN *currentRunPos = head;
- while (currentRunPos != NULL) {
- int runnerFound = 0; // assume that the runner has not been found
- RUNNER *currentRunnerPos = headRunner;
- while (currentRunnerPos != NULL) {
- if (strcmp(currentRunPos->name,currentRunnerPos->name) == 0) {
- currentRunnerPos->distance += currentRunPos->distance;
- currentRunnerPos->duration += currentRunPos->duration;
- runnerFound = 1;
- break; // quit the while loop as the runner has been found
- }
- currentRunnerPos = currentRunnerPos->next;
- }
- // Create a new runner if the runner was not found and set his data
- if (!runnerFound) {
- RUNNER *newRunner = malloc(sizeof(RUNNER));
- newRunner->distance = currentRunPos->distance;
- newRunner->duration = currentRunPos->duration;
- strcpy(newRunner->name, currentRunPos->name);
- newRunner->next = headRunner;
- headRunner = newRunner;
- }
- currentRunPos=currentRunPos->next;
- }
Add Comment
Please, Sign In to add comment