0% found this document useful (0 votes)
4 views10 pages

Data Structures Case Study

This case study presents a task management system using a singly linked list to efficiently manage daily tasks. It outlines operations such as insertion, deletion, searching, and displaying tasks, while emphasizing the advantages of dynamic memory allocation. The system is practical for various applications, including simple task managers and productivity tools.

Uploaded by

joshkoshy977
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views10 pages

Data Structures Case Study

This case study presents a task management system using a singly linked list to efficiently manage daily tasks. It outlines operations such as insertion, deletion, searching, and displaying tasks, while emphasizing the advantages of dynamic memory allocation. The system is practical for various applications, including simple task managers and productivity tools.

Uploaded by

joshkoshy977
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Case Study: Managing a To-Do List Using a Singly Linked List

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.

Why Singly Linked List?


 Dynamic memory allocation — no need to define size in
advance.
 Easy insertion and deletion at any position.
 Efficient for sequential data like 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.

Advantages of This System:


 Easy to manage tasks dynamically.
 No memory waste due to fixed size.
 Better than arrays for frequent insert/delete.

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>

#define SIZE 100

// Node structure
struct Node {
char task[SIZE];
struct Node* next;
};

struct Node* head = NULL;

// Insert at beginning (for urgent tasks)


void insertAtBeginning(char* newTask) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct
Node));
strcpy(newNode->task, newTask);
newNode->next = head;
head = newNode;
}

// Insert at end (for normal tasks)


void insertAtEnd(char* newTask) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct
Node));
strcpy(newNode->task, newTask);
newNode->next = NULL;

if (head == NULL) {
head = newNode;
return;
}

struct Node* temp = head;


while (temp->next != NULL)
temp = temp->next;

temp->next = newNode;
}

// Delete task by name


void deleteTask(char* taskToDelete) {
struct Node* temp = head;
struct Node* prev = NULL;

while (temp != NULL && strcmp(temp->task, taskToDelete) != 0) {


prev = temp;
temp = temp->next;
}

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);
}

// Count number of tasks


int countTasks() {
int count = 0;
struct Node* temp = head;
while (temp != NULL) {
count++;
temp = temp->next;
}
return count;
}
// Display the task list
void displayTasks() {
struct Node* temp = head;
if (temp == NULL) {
printf("No tasks in the list.\n");
return;
}
printf("Current Tasks:\n");
while (temp != NULL) {
printf("- %s\n", temp->task);
temp = temp->next;
}
}

// Main function to demonstrate functionality


int main() {
insertAtEnd("Submit Assignment");
insertAtBeginning("Attend Urgent Meeting");
insertAtEnd("Buy Groceries");

displayTasks();
printf("\nAfter deleting 'Buy Groceries':\n");
deleteTask("Buy Groceries");
displayTasks();

printf("\nSearching for 'Attend Urgent Meeting':\n");


searchTask("Attend Urgent Meeting");

printf("\nTotal tasks: %d\n", countTasks());

return 0;
}

Output:

You might also like