Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement C++ stack and queue

Shulou Source: shulou.com Published: 2022-06-02 09:29:14 09月15日 Update

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

Tags: Queues programs tests content learning practicality deeper interest practicality practicality simplicity of operation methods more friends programs websites channels queries Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Apple OPPO Reno Shulou Tech Info MariaDB