-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdsaf23.c
More file actions
62 lines (49 loc) · 1.36 KB
/
dsaf23.c
File metadata and controls
62 lines (49 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <stdlib.h>
struct Match {
int player1;
int player2;
int winner;
struct Match* next;
};
struct Match* head = NULL;
void recordResult(int player1, int player2, int winner) {
struct Match* newMatch = (struct Match*)malloc(sizeof(struct Match));
newMatch->player1 = player1;
newMatch->player2 = player2;
newMatch->winner = winner;
newMatch->next = NULL;
if (head == NULL) {
head = newMatch;
} else {
struct Match* temp = head;
while (temp->next != NULL)
temp = temp->next;
temp->next = newMatch;
}
}
void getPlayerPath(int playerId) {
struct Match* temp = head;
int found = 0;
printf("Match history for Player %d:\n", playerId);
while (temp != NULL) {
if (temp->player1 == playerId || temp->player2 == playerId) {
printf(" %d vs %d -> Winner: %d\n",
temp->player1, temp->player2, temp->winner);
found = 1;
}
temp = temp->next;
}
if (!found)
printf(" No matches found for player %d.\n", playerId);
}
int main() {
recordResult(1, 2, 1);
recordResult(3, 4, 4);
recordResult(1, 4, 1);
recordResult(2, 3, 3);
getPlayerPath(1);
getPlayerPath(3);
getPlayerPath(5);
return 0;
}