How to use C++ to realize the function of pushing boxes and additional withdrawal
This article introduces the relevant knowledge of "how to use C++ to achieve additional withdrawal". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Coding environment: VS2019
The retracement function realized by using the chain stack.
LinkStack.h
# implementation of pragma once/*** chain stack * * / # ifdef _ cplusplusextern "C" {# endif # include # include # includeusing namespace std; # define OK 1#define ERROR 0#define OVERFLOW-2//typedef int Data; struct Point {int r; int c; int data;}; typedef struct _ State {Point pos [3];} Data,State; typedef struct StackNode {Data data; struct StackNode* next;} StackNode, * LinkStack / / initialization of algorithm 1 chain stack (headless node) void InitStack (LinkStack& S) {/ / construct an empty stack S, stack top pointer empty S = NULL; / / return OK;} / / algorithm 2 chain stack void Push (LinkStack& S, Data e) {/ / insert element e LinkStack p; p = new StackNode; / / generate a new node p-> data = e at the top of the stack / / set the new node data field to e p-> next = S; / / insert the new node into the top of the stack (similar to pre-interpolation, except without a header node) S = p; / modify the top pointer of the stack to p printf ("ok\ n"); / / return OK } / / algorithm 3 void Pop (LinkStack& S) {/ / delete the top element of S and return its value LinkStack p; if (S = = NULL) return with e; / empty / / e = S-> data; / / assign the top element to e p = S; / / use p to temporarily save the top element space in case S = S-> next is released / / modify the top pointer delete p; / / release the space of the elements at the top of the original stack / / return OK;} / / algorithm 4 fetch the top element of the chain stack Data GetTop (LinkStack S) {/ / return the top element of S without modifying the top pointer if (S! = NULL) / / stack non-empty return S-> data / / returns the value of the top element of the stack. The top pointer of the stack is unchanged} bool empty (LinkStack& S) {if (S = = NULL) return true; else return false;} / void empty (LinkStack& S) {/} # ifdef _ cplusplus} # endif/*int main () {LinkStack s; int choose, flag = 0; SElemType j, t; cout