Question
I need help with a c++ code, i am new learner on stack, please help me write Stack.cpp according to Stack.h provided, thanks(Notes: That data
I need help with a c++ code, i am new learner on stack, please help me write Stack.cpp according to Stack.h provided, thanks(Notes: That data structure is a singly linked list in which pushed items are placed at the tail of the linked list. Similarly, popped items will be removed from the tail of the list.)
class Stack {
private:
// Desc: Nodes for a singly-linked list class StackNode { public: int data; StackNode * next; };
// Desc: head = ptr to the first StackNode (NULL if empty) // tail = ptr to the last StackNode (NULL if empty) StackNode * head; StackNode * tail;
public:
// Desc: Constructor // Post: Stack is empty Stack();
// Desc: Destructor // Post: deallocate memory and do other cleanup for the class object and its class members when the object is destroyed ~Stack();
// Desc: Insert element x to the top of the stack. // Post: add items at the tail of the linked list void push(int x);
// Desc: Remove and return element at the top of the stack. // Pre: stack is not empty // Post: remove items from the tail of the list int pop();
// Desc: Return the topmost element of the stack. // Pre: stack is not empty // Post: int peek() const;
// Desc: describe if the stack is empty // Post: return true if empty bool isEmpty() const; };
/*Referring to the proposed implementation , could you please analyze the total running time required to push n items to the Stack. Next, analyze the total running time required to pop those n items from the Stack. A detailed analysis is expected, it will be helpful to my learning,:)*/
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started