65,210
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
#include <vector>
typedef struct NodeT
{
NodeT * prev;
NodeT * next;
std::string url;
NodeT(NodeT * p, NodeT * n, std::string u)
{
prev = p;
next = n;
url = u;
}
} Node;
using namespace std;
int main()
{
string s1;
Node *p;
p = new NodeT(0, 0, "http://www.acm.org/");
while (cin >> s1)
{
if (s1 == "VISIT")
{
cin >> s1;
p->next = new NodeT(p, 0, s1);
p = p->next;
cout << p->url << endl;
}
else if (s1 == "BACK")
{
if (p->prev != 0)
{
p = p->prev;
cout << p->url << endl;
}
else
cout << "Ignored" << endl;
}
else if (s1 == "FORWARD")
{
if (p->next != 0)
{
p = p->next;
cout << p->url << endl;
}
else
cout << "Ignored" << endl;
}
else
break;
}
}
没技术含量的问题。
双向链表搞定