poj——1363 栈的使用
#include <iostream> using namespace std; typedef struct Node{ int info; Node * link; }Node; typedef struct LinkStack{ Node * top; }LinkStack; int push(LinkStack * stack, int x){ Node * p = new Node; p->info = x; p->link = stack->top; stack->top = p; return 1; } int pop(LinkStack * stack){ if (stack->top == NULL){ printf("栈为空!\n"); return -1; } else { Node * p; p = stack->top; stack->top = stack->top->link; int t = p->info; return t; } } int main(){ int train; while(scanf("%d",&train)&&train){ int trains[1001]; while(1){ scanf("%d",&trains[0]); if(trains[0]==0){ printf("\n"); break; } else { for(int x=1;x<train;x++) scanf("%d",&trains[x]); } LinkStack * stack = new LinkStack; stack->top = NULL; int num=0; for(int i=0;i<train;i++){ push(stack,i+1); while(stack->top!=NULL&&stack->top->info==trains[num]){ pop(stack); num++; } } if (num==train) cout << "Yes" << endl; else cout << "No" << endl; } } }
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步