Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Examine the following declarations and definitions for array-based implementatio

ID: 3735805 • Letter: E

Question

Examine the following declarations and definitions for array-based implementations for Stack and Queue ADTs. Assume that exception class PushOnFullStack and class PopOnEmptyStack have been defined and are available. Read the following code segment and fill in blank #3.

class StackType
{
public:
StackType();
void Push(StackItemType item);
void Pop();
private:
int top;
ItemType items[MAX_STACK];
};
void StackType::StackType()
{
top = -1;
}
void StackType::Push(ItemType item)
__________________ // 1
___________________; // 2
__________________; // 3
___________________; // 4
}
class QueType
{
public:
// prototypes of QueType operations go here
private:
int front;
int rear;
ItemType items[MAX_QUEUE];
}
void QueType::QueType()
{
front = MAX_QUEUE - 1;
rear = MAX_QUEUE - 1;
}
Boolean QueType::IsEmpty()
{
return (rear == front);
}
void QueType::Enqueue(ItemType item)
{
____________________; // 5
____________________; // 6
}

Explanation / Answer

class StackType

{

public:

StackType();

void Push(StackItemType item);

void Pop();

private:

int top;

ItemType items[MAX_STACK];

};

void StackType::StackType()

{

top = -1;

}

void StackType::Push(ItemType item)

if(IsFull()) // 1

throw FullStack(); // 2

top++; // 3

items[top] = item; // 4

}

class QueType

{

public:

// prototypes of QueType operations go here

private:

int front;

int rear;

ItemType items[MAX_QUEUE];

}

void QueType::QueType()

{

front = MAX_QUEUE - 1;

rear = MAX_QUEUE - 1;

}

Boolean QueType::IsEmpty()

{

return (rear == front);

}

void QueType::Enqueue(ItemType item)

{

rear = (rear +1) % MAX_QUEUE; // 5

items[rear] = item; // 6

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote