Skip to content

Conversation

alka-tripathi
Copy link

  1. add(int data)

Purpose: Add an element at the end of the queue.

Behavior:

If the queue is full (isOverflow() returns true), it prints a message and does not add the element.

Otherwise, increments rear and stores the new element in the array.

Time Complexity: O(1)

  1. remove()

Purpose: Remove the element from the front of the queue.

Behavior:

If the queue is empty (isEmpty() returns true), it prints a message and returns -1.

Otherwise, it removes the front element, shifts all remaining elements one step forward, and decrements rear.

Time Complexity: O(n) — due to shifting elements.

  1. peek()

Purpose: Get the element at the front of the queue without removing it.

Behavior:

If the queue is empty, prints a message and returns -1.

Otherwise, returns the first element of the array.

Time Complexity: O(1)

  1. isEmpty()

Purpose: Check whether the queue has any elements.

Behavior:

Returns true if rear == -1 (no elements in the queue), otherwise false.

Use Case: Helps prevent errors when removing or peeking from an empty queue.

  1. isOverflow()

Purpose: Check whether the queue is full.

Behavior:

Returns true if rear == size - 1 (no more space to add elements), otherwise false.

Use Case: Helps prevent adding elements beyond the array size.

#5959 #queue #165

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.75%. Comparing base (9484c7e) to head (772a5bc).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #6682   +/-   ##
=========================================
  Coverage     75.75%   75.75%           
- Complexity     5772     5773    +1     
=========================================
  Files           703      703           
  Lines         19777    19777           
  Branches       3832     3832           
=========================================
+ Hits          14982    14983    +1     
  Misses         4215     4215           
+ Partials        580      579    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants