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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.