Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Segmentation fault core dump. I keep getting this error when I try to run my program. When I run my debugger it says it triggers

Segmentation fault core dump. I keep getting this error when I try to run my program. When I run my debugger it says it triggers when this code is enabled:

//executive.cpp

if(myStack->isEmpty() == true) { std::cout<<"The elevator is empty "; }

//stack.cpp

bool Stack::isEmpty() const { return(m_top->Empty()); }

//Node.cpp

template Node::Node(T entry) { m_entry = entry; m_next = nullptr; }

template T Node::getEntry() const { return(m_entry); }

template void Node::setEntry(T entry) { m_entry = entry; }

template Node* Node::getNext() const { return(m_next); }

template void Node::setNext(Node* next) { m_next = next; } template bool Node::Empty() const { if(m_entry == nullptr) { return(true); } else { return(false); } }

//stack.cpp

template Stack::Stack(const Stack& orig) { Node* origNodes = orig.m_top(); while(origNodes != nullptr) { push(origNodes-> getEntry()); origNodes = origNodes -> getNext(); numPeople++; } }

template void Stack::operator=(const Stack& rhs) { Node* origNodes = rhs.m_top; while(origNodes != nullptr) { push(origNodes-> getEntry()); origNodes = origNodes -> getNext(); } } template void Stack::push(T entry) { Node* temp = m_top; temp -> setEntry(entry); if (isEmpty()!= true) { m_top = temp; temp->setNext() = nullptr; } else // Otherwise, insert newNode before top { temp->setNext() = m_top; m_top = temp; } } template bool Stack::isEmpty() /// this is where it says there is the core dump { if(m_top == nullptr ) {return (true);} else { return(false); } }

template void Stack::pop() { if(isEmpty != true) { Node* temp = m_top; m_top= temp-> getNext(); numPeople--;} else {

} }

template T Stack::peek() { if(isEmpty() != true) { return(m_top-> getEntry()); } else { return("No one"); } }

template Stack::~Stack() { Node *nextNode,*nodePtr; nodePtr -> peek(); while (nodePtr != nullptr) { nextNode = nodePtr->getNext(); delete[] nodePtr, nextNode, m_top; nodePtr = nextNode; } }

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

More Books

Students also viewed these Databases questions