Data Structures Case Study
Data Structures Case Study
Objective:
To create a simple task management system using a singly linked list
that helps users manage a dynamic list of daily tasks with basic
operations like insertion, deletion, search, and display.
Introduction:
Task management is a common need in day-to-day life. Whether you
are a student managing assignments or a professional juggling
meetings and deadlines, a to-do list is essential. This case study
demonstrates how a singly linked list can be used to manage such a
list dynamically and efficiently.
Problem Statement:
Design a to-do list system where:
Urgent tasks should be added at the beginning.
Normal tasks should be added at the end.
Completed tasks can be removed.
The list of pending tasks can be viewed at any time.
The user can search for a task and count total tasks.
Operations to Implement:
1. Insert at Beginning – For high-priority tasks.
2. Insert at End – For regular tasks.
3. Delete by Value – Remove completed tasks.
4. Search – Check if a task exists.
5. Count – Total tasks pending.
6. Display – Show all tasks.
Example Scenario:
Let’s walk through a sample execution:
1. Insert End: Add "Submit Assignment"
2. Insert Beginning: Add "Attend Urgent Meeting"
3. Insert End: Add "Buy Groceries"
4. Display List:
o Attend Urgent Meeting → Submit Assignment → Buy
Groceries
5. Delete "Buy Groceries"
6. Search "Attend Urgent Meeting" → Found
7. Count Tasks → 2
8. Display List:
o Attend Urgent Meeting → Submit Assignment
Real-World Relevance:
This can be used in:
Simple CLI-based task manager.
Backend logic for task reminder apps.
Scheduling systems for embedded devices or productivity tools.
Conclusion:
Using a singly linked list for a task management system is a practical
and efficient approach. It provides flexibility and ease of
implementation, especially in scenarios where tasks change
frequently. The simplicity of this system makes it suitable for
students, beginner developers, or small productivity tools.
Workflow:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Node structure
struct Node {
char task[SIZE];
struct Node* next;
};
if (head == NULL) {
head = newNode;
return;
}
temp->next = newNode;
}
if (temp == NULL) {
printf("Task not found.\n");
return;
}
if (prev == NULL)
head = temp->next;
else
prev->next = temp->next;
free(temp);
printf("Task \"%s\" deleted.\n", taskToDelete);
}
// Search for a task
void searchTask(char* taskToFind) {
struct Node* temp = head;
while (temp != NULL) {
if (strcmp(temp->task, taskToFind) == 0) {
printf("Task \"%s\" found.\n", taskToFind);
return;
}
temp = temp->next;
}
printf("Task \"%s\" not found.\n", taskToFind);
}
displayTasks();
printf("\nAfter deleting 'Buy Groceries':\n");
deleteTask("Buy Groceries");
displayTasks();
return 0;
}
Output: