The subject of the ability to examine code. Can also be said to be the algorithm water problem, hehe.
Recommended for beginners to practice code skills.
To increase the difficulty of using pure C to implement the stack, then it is a bit difficult, you can use the array to simulate the ring stack. Long, I will use the STL directly.
#include <stdio.h> #include <iostream> #include <stack> #include <string>using namespace std; int main () {stack<string> forward;stack<string> backward;string cur = "http://www.acm.org/"; string cmd; while (Cin>>cmd) {if (cmd = = "QUIT") break;if (cmd = = "VISIT") {Backward.push (cur); Cin>>cur;puts (Cur.c_str () ); forward = Stack<string> ();} else if (cmd = = "Back") {if (Backward.empty ()) {puts ("ignored");} Else{forward.push (cur); cur = backward.top (); Backward.pop ();p UTS (CUR.C_STR ());}} else if (cmd = = "FORWARD") {if (Forward.empty ()) {puts ("ignored");} Else{backward.push (cur); cur = forward.top (); Forward.pop ();p UTS (CUR.C_STR ());}} return 0;}