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

Given the following stack declaration, which of the following function definitio

ID: 3595393 • Letter: G

Question

Given the following stack declaration, which of the following function definitions would correctly push an item onto the stack?
struct StackFrame
{
char data;
StackFrame *link;
};
typedef StackFrame* StackFramePtr;

class Stack
{
public:
Stack( );
Stack(const Stack& a_stack);
~Stack( );
void push(char the_symbol);
char pop( );
bool empty( ) const;
private:
StackFramePtr top;
};


a) void Stack::push(char the_symbol)
{
StackFrame temp_ptr;
temp_ptr = new StackFrame;
temp_ptr->data = the_symbol;
temp_ptr->link = top;
top = temp_ptr;
}


b) void Stack::push(char the_symbol)
{
StackFramePtr temp_ptr;
temp_ptr = new StackFrame;
temp_ptr->data = the_symbol;
temp_ptr->link = top;
top = temp_ptr;
}


c) void Stack::push(char the_symbol)
{
StackFramePtr temp_ptr;
temp_ptr->data = the_symbol;
temp_ptr->link = top;
top = temp_ptr;
}


d) void Stack::push(char the_symbol)
{
StackFramePtr temp_ptr;
temp_ptr = new StackFrame;
temp_ptr->data = the_symbol;
temp_ptr->link = top;
}

Given the following stack declaration, which of the following function definitions would correctly push an item onto the stack?
struct StackFrame
{
char data;
StackFrame *link;
};
typedef StackFrame* StackFramePtr;

class Stack
{
public:
Stack( );
Stack(const Stack& a_stack);
~Stack( );
void push(char the_symbol);
char pop( );
bool empty( ) const;
private:
StackFramePtr top;
};


a) void Stack::push(char the_symbol)
{
StackFrame temp_ptr;
temp_ptr = new StackFrame;
temp_ptr->data = the_symbol;
temp_ptr->link = top;
top = temp_ptr;
}


b) void Stack::push(char the_symbol)
{
StackFramePtr temp_ptr;
temp_ptr = new StackFrame;
temp_ptr->data = the_symbol;
temp_ptr->link = top;
top = temp_ptr;
}


c) void Stack::push(char the_symbol)
{
StackFramePtr temp_ptr;
temp_ptr->data = the_symbol;
temp_ptr->link = top;
top = temp_ptr;
}


d) void Stack::push(char the_symbol)
{
StackFramePtr temp_ptr;
temp_ptr = new StackFrame;
temp_ptr->data = the_symbol;
temp_ptr->link = top;
}

Explanation / Answer

b) void Stack::push(char the_symbol)
{
StackFramePtr temp_ptr;
temp_ptr = new StackFrame;
temp_ptr->data = the_symbol;
temp_ptr->link = top;
top = temp_ptr;
}

stack.cpp

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