Question: Part 1 : Circular Array Implementation of Deque ( 1 5 points ) Implement the Deque Class: Create a DequeArray class that implements a deque

Part 1: Circular Array Implementation of Deque (15 points)
Implement the Deque Class:
Create a DequeArray class that implements a deque using a circular array.
Attributes:
arr: The array to store elements.
front: Index of the front element.
rear: Index of the rear element.
size: Current number of elements in the deque.
capacity: Maximum number of elements the deque can hold.
Methods:
is_empty(): Check if the deque is empty.
is_full(): Check if the deque is full.
add_front(item): Add an element at the front.
add_rear(item): Add an element at the rear.
remove_front(): Remove and return the front element.
remove_rear(): Remove and return the rear element.
get_front(): Return the front element without removing it.
get_rear(): Return the rear element without removing it.
Test the Implementation:
Write test cases to validate your deque implementation.
Test edge cases like adding/removing from an empty deque, or adding to a full deque.
Part 2: Extended Operations (15 points)
Extend the Functionality:
Implement the following additional operations in DequeArray:
size(): Return the number of elements in the deque.
clear(): Remove all elements from the deque.
rotate(k): Rotate the deque by k elements. Positive k rotates to the right, negative k rotates to the left.
peek_nth(n): Return the nth element from the front without removing it. The first element has index 0.
Analyze the Performance:
Analyze the time complexity of each operation in the DequeArray implementation.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!