Question: I keep getting a core dumped, what is wrong? define the top() method, which will return the data at the top of the stack (remember

I keep getting a core dumped, what is wrong?  I keep getting a core dumped, what is wrong? define the
top() method, which will return the data at the top of the
stack (remember the "top" of the stack is the newest element) If
stack is empty, return ""; string LLStack: :top() \{ if(head == nullptr)
\{ return ""; I \} else \{ return head->data; \} \} /*

define the top() method, which will return the data at the top of the stack (remember the "top" of the stack is the newest element) If stack is empty, return ""; string LLStack: :top() \{ if(head == nullptr) \{ return ""; I \} else \{ return head->data; \} \} /* */ define the size() method, which will return the number of nodes in the stack int LLStack::size() \{ \} - Create the new Node and initialize the fields of class Node (data and next) - update the head, tail and count accordingly Hint: To update head and tail properly, You have to consider two scenarios: 1. If there is no element in the stack and this is the first one going to the stack * 2. If there is another head in the stack void LLStack: :push(string s) \{ Node * newNode = new Node(s); newNode->data =s; if ( tail ==0){ head = newNode; tail = newNode; newNode->next = nullptr; \} else \{ newNode->next = head; head = newNode; 3 count ++ \} First, Check if the stack is empty or not. If not, update the head, tail and count accordingly. *Don't forget to release memory using delete Hint: To update head and tail properly, You should consider two different scenarios: 1. If LLStack has more than one element 2. If LLStack has exactly one element / void LLStack::pop() \{ if (count == I) \{ delete head; head =nullptr; tail = nullptr; countt+; \} else \{ Node temp = head-> next; delete head; head = temp; count =; \} \}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!