Group5 087 098 108 120
Group5 087 098 108 120
LEADERBOARD SYSTEM
By Team: Group 5
Members :
Rohith
Nishith R
Prashanth Kulal
Pruthvi
PROBLEM STATEMENT
• 2. Deletion:
• To remove a player:
• Find the player by name using a search.
• If the player has no children, remove the node.
• If the player has one child, replace the node with its child.
• If the player has two children, find the inorder successor (minimum node in the right subtree), copy its
data, and remove the successor.
• 3. Search:
• To find a player:
• Compare the player's name with the root node's name.
• Recursively search left or right depending on the alphabetical comparison.
• 4. Update Score:
• To update a player's score:
• Find the player by name.
• Update their score directly in the node.
• Inputs
• Player Name (String): Examples: "John", "Alice", "Mike".
• Player Score (Integer): Examples: 200, 150, 300.
• Number of Top Players (Integer): Examples: 3, 5.
• Outputs
• Player List:
• Example:
• Player: John, Score: 300
• Player: Alice, Score: 200
• Player: Mike, Score: 150
• Search Result:
• Example: "Player found: John, Score: 300."
• Example (non-existent): "Player not found."
• Confirmation Messages:
• Example (addition): "Player John added successfully."
• Example (deletion): "Player John has been removed from the leaderboard."
Test Cases:
// Function prototypes
Node* createNode(char name[], int score);
Node* insertNode(Node* root, char name[], int score);
Node* searchNode(Node* root, char name[]);
Node* deleteNode(Node* root, char name[]);
Node* findMin(Node* root);
void updateScore(Node* root, char name[], int newScore);
void inorderTraversal(Node* root);
void reverseInorderTraversal(Node* root, int* rank, int topN);
void freeTree(Node* root);
void flushInput();
// Main function
int main() {
Node* root = NULL;
int choice, score, newScore, topN;
char name[50];
while (1) {
// Display the menu
printf("\nGaming Leaderboard\n");
printf("1. Add Player\n");
printf("2. Update Player Score\n");
printf("3.View Leaderboard\n");
printf("4. Search Player\n");
printf("5. Delete Player\n");
printf("6. Display Top N Players\n");
printf("7. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
flushInput(); // Clear the input buffer
:
switch (choice) {
case 1:
printf("Enter player name: ");
fgets(name, sizeof(name), stdin);
name[strcspn(name, "\n")] = '\0'; // Remove newline character from name
// Validate score
if (score < 0) {
printf("Error: Score cannot be negative. Please enter a valid score.\n");
break;
}
case 2:
printf("Enter player name to update: ");
fgets(name, sizeof(name), stdin);
name[strcspn(name, "\n")] = '\0'; // Remove newline character from name
// Validate score
if (newScore < 0) {
printf("Error: Score cannot be negative. Please enter a valid score.\n");
break;
}
case 3:
printf("\nLeaderboard:\n");
inorderTraversal(root);
break;
case 4:
printf("Enter player name to search: ");
fgets(name, sizeof(name), stdin);
name[strcspn(name, "\n")] = '\0'; // Remove newline character from name
case 5:
printf("Enter player name to delete: ");
fgets(name, sizeof(name), stdin);
name[strcspn(name, "\n")] = '\0'; // Remove newline character from name
case 6:
printf("Enter number of top players to display: ");
scanf("%d", &topN);
flushInput();
case 7:
freeTree(root);
printf("Exiting...\n");
return 0;
default:
printf("Invalid choice. Please try again.\n");
}
}
return 0;
}
// Create a new node for a player
Node* createNode(char name[], int score) {
Node* newNode = (Node*)malloc(sizeof(Node));
strcpy(newNode->name, name);
newNode->score = score;
newNode->left = newNode->right = NULL;
return newNode;
}
// Insert based on score, smaller score goes to the left, larger to the right
if (score < root->score) {
root->left = insertNode(root->left, name, score);
} else if (score > root->score) {
root->right = insertNode(root->right, name, score);
} else {
printf("Player with the same score already exists!\n");
}
return root;
}
// Node with two children: get the inorder successor (smallest in the right subtree)
Node* temp = findMin(root->right);
strcpy(root->name, temp->name);
root->score = temp->score;
root->right = deleteNode(root->right, temp->name);
}
return root;
}
// In-order traversal (ascending order of scores)
void inorderTraversal(Node* root) {
if (root) {
inorderTraversal(root->left);
printf("Player: %s, Score: %d\n", root->name, root->score);
inorderTraversal(root->right);
}
}
• Conclusion
• The Gaming Leaderboard System effectively manages player
rankings using a Binary Search Tree (BST), allowing
functionalities like adding, updating, deleting, searching, and displaying
the leaderboard. It ensures efficient operations with a user-friendly
interface.
• Future Enhancements
1.Priority Queue: Implement dynamic ranking based on additional
criteria.
2.Database Integration: Store data persistently for long-term use.
3.Web Interface: Create a web-based version for online interaction.
4.Graphical Visualization: Add charts for player rankings.
5.User Profiles: Introduce authentication for tracking player
progress.