Question: C++ Write a program that opens a text file, and displays the contents and stores the contents into a stack of characters. The program will
C++ Write a program that opens a text file, and displays the contents and stores the contents into a stack of characters. The program will then pop the characters from the stack, and save them in a second file in reverse order, then open the second file and read and display the contents.
here is the class
template
StackNode *top;
public: DynStack() { top = nullptr; } void push(T); void pop(T &); bool isEmpty(); }; //********************************************************* // Member function push pushes the argument onto the stack. * //*********************************************************
template
// Allocate a new node & store Num 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 = nullptr; } 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. * //*********************************************************
template
if (isEmpty()) { cout << "The stack is empty. "; } else // pop value off top of stack { num = top->value; temp = top->next; delete top; top = temp; } }
//********************************************************* // Member function isEmpty returns true if the stack * // is empty, or false otherwise. * //*********************************************************
template
if (!top) { status = true; } return status; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
