Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please use the template provided above Problem Statement In this problem you will be implementing a Stack using a Singly Linked List. Implement the following
Please use the template provided above
Problem Statement In this problem you will be implementing a Stack using a Singly Linked List. Implement the following functionalities of a stack ADT using a singly linked list. push(x) -- Push element x on the stack. popO -- Remove the element from the top of the stack. peek -- Return the element at the top of the stack. isEmpty -- Return whether the stack is empty. Constraints The values in the stack are integers, i.e. x is an integer. Note Your Stack implementation (class Stack_LL) should use the Node Class given below to build your Singly Linked List. class Node { public: int data; Node* next; Node(int val) {data = val; next = nullptr;} Node(int val, Node* node) {data = val; next = node; } }; Hint topptr is a pointer that points to the top element of the stack. You could treat it as a head pointer for your linked list implementation. topPtr is a private data member that is available in the Stack_LL class. topPtr 10 +18+18+o 60 Test cases We will be testing your code and implementing the main() function. A description of the test cases is given below. The first line of the input is the operation we will be calling on your Stack object. The second line of input is the parameters that are passed to the corresponding operation in Line 1. The Output is the return value of the function call to the corresponding operation in Line 1. null in output means the function doesn't return anything. They are of type void. You may assume that all operations are valid (e.g. no pop or peek operations will be called on an empty stack). 1 class Stack_LL { 2 private: 3 1/ topptr points to the top element of the stack 4 public: 5 Stack_LLO; 6 -Stack_LL(; 7 bool isEmpty() const; 8 void push(int newItem); 9 void pop(; 10 int peek () const; 11 }; 12 13 Stack_LL::Stack_LL() { 14 15 ) 16 17 Stack_LL::-Stack_LL) { 18 19} 20 21 bool Stack_LL::isEmpty() const { 22 23 } 24 25 void Stack_LL::push(int newItem) { 26 27 } 28 29 void Stack_LL::pop() { 30 31 } 32 33 int Stack_LL::peek() const { 34 35 }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