zoukankan      html  css  js  c++  java
  • 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("栈为空!
    ");
    		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("
    ");
    				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;
    		}
    	}	
    }
    

      

  • 相关阅读:
    查看tls指纹
    并行流
    方法引入2
    方法引入
    Optional.ofNullable
    stream.filter
    stream.skip limit
    反射
    Optional orElseGet
    nginx 预压缩(gzip)
  • 原文地址:https://www.cnblogs.com/lvcoding/p/7486501.html
Copyright © 2011-2022 走看看