Question: Complete the queue and de queue fcns for a queue in the following code: Quell: #include #include QueueLL.hpp using namespace std; QueueLL::QueueLL() { queueFront =
Complete the queue and de queue fcns for a queue in the following code: Quell: #include <iostream> using namespace std; QueueLL::QueueLL() QueueLL::~QueueLL() bool QueueLL::isEmpty() // TODO // TODO Complete this function, handle the case when you're enqueuing in an empty queue //TODO int QueueLL::peek() driver.cpp (make sure quell works w this) #include #include "QueueLL.hpp" using namespace std; int main() { // test queues QueueLL queue; // TC1: queue empty after created? cout << "(1) "; cout << "Queue empty? "; cout << (queue.isEmpty() ? "yes." : "no."); if(!queue.isEmpty()) cout << " -- FAIL"; cout << endl; // TC2: Push items // TODO - Complete your enqueue function cout << "(2) "; cout << "Enqueuing 1, 2, 3" << endl; queue.enqueue(1); queue.enqueue(2); queue.enqueue(3); // TC3: Queue not empty after pushing items cout << "(3) "; cout << "Queue empty? "; cout << (queue.isEmpty() ? "yes." : "no."); if(queue.isEmpty()) cout << " -- FAIL"; cout << endl; // TC4: peek cout << "(4) "; int topKey = queue.peek(); cout << "Peeked key: " << topKey; if(topKey != 1) { cout << " -- FAIL"; } cout << endl; // TC5: pop items // TODO: Complete your dequeue function cout << "(5) Dequeuing everything" << endl; int testint = 0; int testvals[] = {1, 2, 3}; while(!queue.isEmpty()) { topKey = queue.peek(); queue.dequeue(); cout << " - dequeue: " << topKey; if(topKey != testvals[testint++]) { cout << " -- FAIL"; } cout << endl; } if(testint != 3) cout << " -- FAIL" << endl; return 0; }
#include "QueueLL.hpp"
{
queueFront = nullptr;
queueEnd = nullptr;
}
{
while( !isEmpty() )
dequeue();
}
{
/*if(queueFront == nullptr || queueEnd == nullptr)
return true;
return false;*/
return (!queueFront || !queueEnd);
}
void QueueLL::enqueue(int key)
{
Node *nn = new Node;
nn->key = key;
nn->next = nullptr;
}
void QueueLL::dequeue()
{
if(!isEmpty())
{
// TODO Complete this function, handle the case when your queue becomes empty after dequeuing
}
else{
cout<<"queue is empty. can not deque"<<endl;
}
}
{
if( !isEmpty() )
return queueFront->key;
else
{
cout<< " queue is empty. can not peek"<<endl;
return -1;
}
//return 0;
}
Step by Step Solution
3.42 Rating (165 Votes )
There are 3 Steps involved in it
First TODO Since we are enqueuing in an empty queue simply make the fist and last pointer ... View full answer
Get step-by-step solutions from verified subject matter experts
