The stack has the following features: first-in-first-out. We can use it to temporarily store data. In the development of the canvas, I used the stack to save each step of the user's operations, when you click Cancel, you can extract the image from the stack and restore it. This is also the principle of browser forward and backward, but it only saves web pages. You can use the STL to easily use stacks instead of complex function definitions. Let's look at the following examples and hope that you can use the following examples to understand how to use the stacks in STL and how to use the stacks.
# Include <graphics. h>
# Include <iostream>
# Include <conio. h>
# Include <stack>
Using Namespace STD;
Int Main ()
{
Stack <image> S1;
Image IMG, HH;
Initgraph ( 600 , 600 );
// Screen push stack
Cleardevice ();
Getimage (& IMG, 0 , 0 , 600 , 600 );
S1.push (IMG );
// Drawing circle pressure Stack
Circle ( 100 , 100 ,50 );
Getimage (& IMG, 0 , 0 , 600 , 600 );
S1.push (IMG );
Getch ();
// Drawing line pressure Stack
Line ( 1 , 1 , 600 , 600 );
Getimage (& IMG, 0 , 0 , 600 , 600 );
S1.push (IMG );
Getch ();
// Clear Screen
Cleardevice ();
Getch ();
// Stack output in sequence
HH = s1.top ();
Putimage ( 0 ,0 , & HH );
Getch ();
S1.pop ();
HH = s1.top ();
Putimage ( 0 , 0 , & HH );
Getch ();
S1.pop ();
HH = s1.top ();
Putimage ( 0 , 0 , & HH );
Getch ();
S1.pop ();
}