C++ language, linked stack implementation
Experiment content:
- Program to implement the following functions of the stack:
(1) Establish a sequential stack of length n, with element types defined by yourself, and output the values of each element in the stack.
(2) Push data element e onto the stack, and output the values of each element in the sequential stack after the push operation.
(3) Pop the top element from the sequential stack, and output the value of the popped element and the values of each element in the sequential stack after the pop operation.- Program to implement the following functions of the queue:
(1) Establish a circular queue of length n, with element types defined by yourself, and output the values of each element in the queue.
(2) Enqueue data element e, and output the values of each element in the queue after the enqueue operation.
(3) Dequeue the front element of the circular queue, and output the value of the dequeued element and the values of each element in the queue after the dequeue operation.- Program to implement the following functions of the linked stack:
Establish a linked stack of length n, with element types defined by yourself, and implement typical operations such as stack initialization, push, and pop.
Overall, the first is to implement the basic operations of the sequential stack and linked stack: push operation (Push), pop operation (Pop), get top element (Top), check if the stack is empty (IsEmpty), check if the stack is full (IsFull), get the number of elements in the stack (Size), display all elements in the stack (PrintStack), clear all elements in the stack (Clear). The second is to implement the basic operations of the queue: enqueue operation (Push), dequeue operation (Pop), get front element (Front), check if the queue is empty (IsEmpty), check if the queue is full (IsFull), get the number of elements in the queue (Size), display all elements in the queue (PrintQueue), clear all elements in the queue (Clear). It is still encapsulating a template class. Initialization and destruction operations are implemented in the constructor and destructor functions.
@[TOC](Table of Contents)
Sequential Stack#
Definition of Sequential Stack Operation Class#
Main Operations#
(1) Constructor and Destructor#
(2) Check if the Stack is Empty or Full#
(3) Push Operation#
Store element data at the top of the stack, increment top value
(4) Get Top Element#
Get the top element, do not pop
(5) Get Number of Elements in the Stack#
(6) Pop Operation#
Pop the top element, decrement top value
(7) Display All Elements in the Sequential Stack#
Complete Code#
Linked Stack#
Definition of Linked Stack Node#
Definition of Linked Stack Operation Class#
Main Operations#
(1) Constructor and Destructor#
(2) Check if the Stack is Empty or Full#
(3) Push Operation#
Store element data at the top of the stack
(4) Get Top Element#
(5) Get Number of Elements in the Stack#
(6) Pop Operation#
Pop the top element and delete it from the stack