Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer this computer science question with 3 files (queue.h, queue.cpp, main.cpp) main.cpp queue.h queue.cpp The array based queue implementation uses a circular list, maintaining

Please answer this computer science question with 3 files (queue.h, queue.cpp, main.cpp) image text in transcribed
main.cpp
image text in transcribed
queue.h
image text in transcribed
queue.cpp
image text in transcribed
image text in transcribed
The array based queue implementation uses a circular list, maintaining a frontindex and a backindex. The circular list wastes one location in the array, so an array of size 5 will only hold a maximum of 4 queue items. Let's go through an example of a queue with a MAX size of 5. x- represents unknown value // beginning empty queue troatIndex, backIndex-o xxx x1 // push (5) // frontindex " , backIndex " 1 push (7 trontIndex -0, backIndex 2 5 7xx push(3 trontIndex-o, backIndex3 15 73xx / pop0 // front Index-, backIndex-3 // pop0 trontIndex 2, backIndex3 xx3xx // push 12) frontIndex-2, backIndex-4 Ixx32 x // push (6) / trontIndex 2, backIndexo0 Ix x 3 2 61 / push (8) II trontIndex - 2. backIndex 18x32 6 push (O) erzor, queue is full 18 x32 61 // pop0 // frontIndex - 3, backIndex 8 x x 2 6 push (1) trontIndex 3, backIndex2 18 1x26] 2 Testing Queue class 4 @author xxx 5 @date xxx 6 8 #includeiostream #include "queue . h" 10 11 using namespace std; 12 void testQueue) ( 14 Queue st; 15 16 /TODO (me) main program 20 int main) ( testQueue(); cout 12 #include iostream> 13 #include "queue . h" 14 15 using namespace std 16 17 11 default constructor 18 Queue::Queue)t 19 IITODO (me) 20 21 22 11 empty destructor, let compiler define it 23 Queue : :-Queue()# default; 24 25 1 return true if queue is empty 26 bool Queue::empty() const f 21/TODO (me) 23 return true; 30 return true if queue is full bool Queue: :full) const f /TODO(me) return true; add item to back of queue after pushiie) 41 void Queue:: push(const int &value) f 42 if(full()) 43 44 1/TODO (me) 45 46 47 11 remove item from front of queue 48 I [2 7 10] 49 // after pop() 50 void Queue: : pop) throw std::out_of_range("push called on full queue"); i-51 f (empty()) 52 throw std::out_of_range ("pop called on empty queue"); 53I/TODO(me) const int &Queue: :front() const f if (empty(O) throw std: :out_of_range ("front called on empty queue"); /TODO (me) return 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions