• 顺序栈的初始化,建立,插入,查找,删除。


    ////////////////////////////////////////////
    //顺序栈的初始化,建立,插入,查找,删除。//
    //Author:Wang Yong				  		  //	
    //Date:	2010.8.19				  		  //
    ////////////////////////////////////////////
    
    
    #include <stdio.h>
    #include <stdlib.h>
    
    #define  MAX 100  				//定义最大栈容量
    
    typedef int ElemType;
    
    ///////////////////////////////////////////
    
    //定义栈类型 
    typedef struct
    {
    	ElemType data[MAX];
    	int top;
    }SeqStack;
    
    ///////////////////////////////////////////
    
    //栈的初始化
    
    SeqStack SeqStackInit()
    {
    	SeqStack s;
    	s.top = -1;
    	return s;
    }
    
    ///////////////////////////////////////////
    
    //判断栈空的算法
    
    int SeqStackIsEmpty(SeqStack s)
    {
    	if(s.top == -1)
    		return 0;
    	else 
    		return 1;
    }
    
    ///////////////////////////////////////////
    
    //进栈的算法
    
    void SeqStackPush(SeqStack &s,ElemType x)
    {
    	if(s.top == MAX-1)				//进栈的时候必须判断是否栈满 
    		printf("stack full\n"); 
    	s.top++;
    	s.data[s.top] = x;
    }
    
    //////////////////////////////////////////
    
    //出栈的算法
    
    ElemType SeqStackPop(SeqStack &s)
    {
    	if(s.top == -1)				//出栈的时候必须判断是否栈空 
    		printf("stack empty\n");
    	ElemType x;
    	x = s.data[s.top];
    	s.top--;
    	return x;
    }
    
    //////////////////////////////////////
    int main()
    {
    	SeqStack  stack;
    	stack = SeqStackInit();
    	printf("请输入进栈的元素:"); 
    	ElemType x;
    	while(scanf("%d",&x) != -1)
    	{
    		SeqStackPush(stack,x);	
    	}
    	printf("出栈的结果:"); 
    	while(stack.top != -1)
    	{
    		printf("%d ",SeqStackPop(stack));
    	}
    	printf("\n");
    	return 0;
    } 
    
    
    
  • 相关阅读:
    git 学习笔记
    参看gitlab版本号
    PHP7.1安装xdebug
    言不由衷
    容器镜像上传和下载
    利用docker搭建ubuntu+nginx+PHP容器
    生产者消费者模式(转)
    白盒测试以及基路径法测试
    分页的简单实现
    排列2(全排列next_permutation 注意格式)
  • 原文地址:https://www.cnblogs.com/newwy/p/1847460.html
Copyright © 2020-2023  润新知