作者:
NCpaste
,
2023-05-25 11:38:13
,
所有人可见
,
阅读 2
#include <iostream>
#include <cstring>
using namespace std;
typedef struct link
{
link * next;
int x;
}*LINK;
string s;
int t;
int main ()
{
int n = 0;
LINK head = new link;
head->next = NULL;
cin >> n;
while (n > 0)
{
n --;
cin >> s;
if (s == "push")
{
cin >> t;
LINK temp = head;
while (temp->next)
{
temp = temp->next;
}
temp->next = new link;
temp = temp->next;
temp->x = t;
temp->next = NULL;
}
else if (s == "pop")
{
LINK temp = head->next;
head->next = temp->next;
delete(temp);
}
else if (s == "empty")
{
if (head->next == NULL)
{
cout <<"YES" << endl;
}
else
{
cout << "NO" << endl;
}
}
else if (s == "query")
{
cout << head->next->x << endl;
}
}
return 0;
}