Array Based Deque

i need to create an array-based deque implementation. It should not use shifting, it needs to allow the items to move around the interior of the array. I have no idea where to begin with this. He usually gives us something to start with but didnt this time. I'm working with this inventory management system. It asks the user if they are using FIFO or LIFO and from there they can buy and sell widgets.
I need to create a deque-based stack and a deque-based queue using the DequeArray implemenation. I really just need to know how to get started...

For the sake of understanding. Could you explain what deque, FIFO, and LIFO mean?

EDIT: After actually reading, I figured out what FIFO and LIFO mean. I also actually looked up deque myself, and I think I understand it now.
Last edited on
It should not use shifting, it needs to allow the items to move around the interior of the array.

This sounds like an oxymoron.
Last edited on
yes, but im not sure how he wants us to go about doing the DequeArray.

and we are supposed to store the index of the front and back to not use shifting
I know an easy way to implement this using a doubly linked list, but that doesn't use an array, so that won't follow your requirements.

Josue Molina makes a point about shifting.

It's possible that you could use a vector, keeping track of your first and last indices to know where you're putting things, but you will lose efficiency, and you'll probably have to shift the elements at some point anyways.

Not sure what you're looking for.
here is what hes assigned
Create an array-based deque implementation (DequeArray). You may use QueueArray from the examples page to get started. Your implementation should not use shifting. Instead, allow the items to move around the interior of the array. To do this, you will need to store both the index of the front and the back. Allow array resizing if the array runs out of room. The (public) operations required by the Deque ADT are as follows:
bool isEmpty()
int size()
void dequeueAll();
T* peek();
void enqueue(T* item);
T* dequeue();
T* peekDeque();
void enqueueDeque(T* item);
T* dequeueDeque();
StackDeque and QueueDeque
Create a deque-based stack and a deque-based queue using your DequeArray implemenation.
Inventory Management
You have a business buying and selling Widgets. There are many ways to keep track of your Widget inventory, but two common ways are LIFO and FIFO. The profit computed using the two methods will be very different. LIFO uses the cost of the Widgets bought last to compute profit. FIFO uses the cost of the Widgets bought first to compute the profit. Thus, since the cost of an item increases over time in an inflationary economy, LIFO reports lower profit than FIFO. LIFO is often used to report income for tax purposes, while FIFO is used to report profit to shareholders.
Write a Widget class to store the cost that you paid for a Widget. The cost is the only instance variable.
Write an InventoryManager class to maintain your inventory and report profit. The constructor accepts an integer (or a boolean) to determine whether LIFO or FIFO is being used. Once selected, this inventory management choice cannot be changed.
Based on the inventory management choice, instantiate a StackDeque or a QueueDeque. When you buy Widgets, push or enqueue the number of Widgets bought, storing the cost that you paid for the Widgets. For example, if you bought 7 Widgets for $5, you will create 7 Widgets, each with cost $5, and you will call push 7 times, once for each Widget. When you sell Widgets, pop or dequeue the number of widgets sold, computing your profit based on the selling price and the cost extracted from each of the Widgets sold. If there are not enough Widgets for the requested number to sell, sell as many widgets as there are (ignore overselling).
Write the following methods in your InventoryManager class:
InventoryManager(int inventory_choice) //LIFO or FIFO
void buyWidgets(double cost, int num_to_buy)
double getTotalProfit()
double sellWidgets(double price, int num_to_sell)
Inventory Driver
Download InventoryDriver (some of this is completed for you) that will allow you to buy and sell Widgets and will report the profit (loss) when you sell Widgets. When the user exits, the InventoryDriver reports the total profit for all transactions. Note that I do not use any global variables. All user interaction is present in the driver. InventoryDriver does not have direct access to the Stack or Queue.

im completely confused about DequeArray. I dont know how to start it, if he wants it in the InventoryManagement header or if i need to make a new file or what
That is really difficult to read.
Topic archived. No new replies allowed.