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->data = the_symbol;
temp_ptr->link = top;
top = temp_ptr;
}
c.
void Stack::push(char the_symbol)
{
StackFramePtr temp_ptr;
temp_ptr = new StackFrame;
temp_ptr->data = the_symbol;
temp_ptr->link = top;
}
d.
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;
}

d.
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;
}

Computer Science & Information Technology

You might also like to view...

Steve Jobs was an early proponent of mobile computer devices.

a. true b. false

Computer Science & Information Technology

How do checked exceptions and runtime exceptions differ in the way that they are handled?

What will be an ideal response?

Computer Science & Information Technology