Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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? image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

Question What happens to my plan if I die?

Answered: 1 week ago