Question: DynIntStack.h // Specification file for the DynIntStack class #ifndef DYNINTSTACK_H #define DYNINTSTACK_H class DynIntStack { private: // Structure for stack nodes struct StackNode { int
DynIntStack.h
// Specification file for the DynIntStack class #ifndef DYNINTSTACK_H #define DYNINTSTACK_H
class DynIntStack { private: // Structure for stack nodes struct StackNode { int value; // Value in the node StackNode *next; // Pointer to the next node };
StackNode *top; // Pointer to the stack top
public: // Constructor DynIntStack() { top = NULL; }
// Destructor ~DynIntStack();
// Stack operations void push(int); void pop(int &); bool isEmpty();
}; #endif
DynIntStack.cpp
#include
//************************************************** // Destructor * // This function deletes every node in the list. * //**************************************************
DynIntStack::~DynIntStack() { StackNode *nodePtr, *nextNode;
// Position nodePtr at the top of the stack. nodePtr = top;
// Traverse the list deleting each node. while (nodePtr != NULL) { nextNode = nodePtr->next; delete nodePtr; nodePtr = nextNode; } }
//************************************************ // Member function push pushes the argument onto * // the stack. * //************************************************
void DynIntStack::push(int num) { StackNode *newNode; // Pointer to a new node
// Allocate a new node and store num there. newNode = new StackNode; newNode->value = num;
// If there are no nodes in the list // make newNode the first node. if (isEmpty()) { top = newNode; newNode->next = NULL; } else // Otherwise, insert NewNode before top. { newNode->next = top; top = newNode; } }
//**************************************************** // Member function pop pops the value at the top * // of the stack off, and copies it into the variable * // passed as an argument. * //****************************************************
void DynIntStack::pop(int &num) { StackNode *temp; // Temporary pointer
// First make sure the stack isn't empty. if (isEmpty()) { cout value; temp = top->next; delete top; top = temp; } }
//**************************************************** // Member function isEmpty returns true if the stack * // is empty, or false otherwise. * //****************************************************
bool DynIntStack::isEmpty() { bool status;
if (!top) status = true; else status = false;
return status; }


I am using C++ .
Homework 12 All the following assignments are selected from Gaddis edition 7. The purpose is that you practice with stakes. First do the reading assignment; Section 18.1-18-3 (pages 1071-1084). Run your code, submit the output and code too. Submit code in a separate, compliable file, do NOT include it in your pdf or text file. 1. Programming challenges 18.2. Dynamic Stack Template, page 1108 [1 point]. Hint: you can use the DynlntStack class from the book examples. Write a program that takes the names of 3 students and their ages from the user, saves this information in 2 stacks, and then prints the names and ages in the terminal. Use the above template to define the 2 stacks [1 point]. 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
