QUEUE06 - Editorial

Problem Link - Queue - To do list

Problem Statement:

Create a program that simulates a to-do list manager using a queue.
The program should allow users to perform the following operations:

  • Add a task to the to-do list.
  • If the task is already present in the list - then ignore the task
  • Display the current to-do list once all tasks have been added

The code given here has implemented queues using arrays.
Update the code to solve the problem.

Approach:

The main idea is to manage a to-do list using a queue structure, where tasks are added only if they do not already exist in the list. A separate array tracks the current tasks in the list, while the queue stores and processes the tasks. The queue follows a circular structure, ensuring that both insertion and deletion are handled efficiently.

addTask(int task):

  • This function adds a new task to the list if it is not already present.

  • It first checks if the current number of tasks (taskListsize) is less than the maximum size of the queue (maxSize).

  • Then, it loops through the taskList to ensure that the task does not already exist. If the task is already present, it skips adding the task.

  • If the task is not found, it enqueues the task using the enqueue function and adds it to the taskList. The taskListsize is incremented to track the number of tasks.

Time Complexity:

  1. enqueue and dequeue operations: Both take constant time, O(1).

  2. addTask function: Takes O(n) time, where n is the current number of tasks, as it checks for duplicates in the task list