How to implement C++ stack and queue
This article mainly explains "how to implement C++ stack and queue". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "how to implement C++ stack and queue".
Definition and implementation of stack
# ifndef Stack_H # define Stack_H # include "List.h" template class Stack: List// stack class definition {public: void Push (Type value) {Insert (value);} Type Pop () {Type p = * GetNext (); RemoveAfter (); return p;} Type GetTop () {return * GetNext ();} List:: MakeEmpty; List:: IsEmpty;}; # endif
Definition and implementation of queues
# ifndef Queue_H # define Queue_H # include "List.h" template class Queue: List// queue definition {public: void EnQueue (const Type & value) {LastInsert (value);} Type DeQueue () {Type p = * GetNext (); RemoveAfter (); IsEmpty (); return p;} Type GetFront () {return * GetNext ();} List: MakeEmpty; List:: IsEmpty;} # endif
Test program
# ifndef StackTest_H # define StackTest_H # include "Stack.h" void StackTest_int () {cout