Used the next seudoucode pseudocode and implement in the next code below run in c ++ this code
What is the output of the following pseudocode, where num1 , num2 , and num3 are integer variables?
num1 = 5
num2 = 1
num3 = 4
aQueue.enqueue(num2)
aQueue.enqueue(num3)
aQueue.dequeue()
aQueue.enqueue(num1 - num2)
num1 = aQueue.peek()
aQueue.dequeue()
num2 = aQueue.peek()
aQueue.dequeue()
cout << num2 << " " << num1 << " " << num3 << endl
____________________________________________________________________________________
a// Created by Frank M. Carrano and Tim Henry.
// Copyright (c) 2013 __Pearson Education__. All rights reserved.
/** ADT queue: Link-based implementation.
Listing 14-3.
@file LinkedQueue.h */
#ifndef _LINKED_QUEUE
#define _LINKED_QUEUE
#include "QueueInterface.h"
#include "Node.h"
#include "PrecondViolatedExcep.h"
template<class ItemType>
class LinkedQueue : public QueueInterface<ItemType>
{
private:
// The queue is implemented as a chain of linked nodes that has
// two external pointers, a head pointer for front of the queue and
// a tail pointer for the back of the queue.
Node<ItemType>* backPtr;
Node<ItemType>* frontPtr;
public:
LinkedQueue();
LinkedQueue (const LinkedQueue& aQueue);
~LinkedQueue();
bool isEmpty() const;
bool enqueue(const ItemType& newEntry);
bool dequeue();
/** @throw PrecondViolatedExcep if the queue is empty */
ItemType peekFront() const throw(PrecondViolatedExcep);
}; // end LinkedQueue
#include "LinkedQueue.cpp"
#endif
The output of the following code will be 1 4 4 because we are using a queue in the function and we input the num2 first and then we input the num3 and then we remove the num3 and then input num1-num2 in the queue so in the queue we have value of 1 at the lowest and value of 4 at the highest index and when we set the value of num1 using the peek function we are providing the value of highest index to the num1 show value of 4 is assigned to num1 and then we remove the value of 4 from the queue and then assign the value of 1 to the num2 by using the peek function. So we get the value of num2 as 1 ,num1 as 4 and num3 as 4 and these values are displayed on the console screen.
Get Answers For Free
Most questions answered within 1 hours.