栈(外部变量的实现)

include <stdbool.h>

include <stdio.h>

include <stdlib.h>

define STACK_SIZE 10

	int content[STACK_SIZE];
	int top=0;//栈最高的位置 
			
	void make_empty(void)
	{
		top=0;//让栈清空 
	}
	bool is_empty(void)
	{
		return top==0;//判断栈是否为空 
	} 
	
	bool is_full(void)
	{
		return top==STACK_SIZE;//判断栈是否已满 
	} 
	
	void push(int i)//压栈 
	{
		if(is_full()) printf("can't push\n");
		else content[top++]=i;
	}
	
	int pop(void)//弹栈 
	{
		if(is_empty()) return -1;
		else return content[--top];
	}
	
	int main()
	{
			int temp;
		for(int i=0;;i++)
		{
			scanf("%d",&temp);
			push(temp);
			if(getchar()=='\n') break;
		}
		for(int i=0;;i++)
		{
			int mid=pop();
			if(mid==-1) break;//判断弹出完毕 
			printf("%d ",mid);
			
		}
	
	}

想不到这个栈有什么应用,如何控制,就弱智地挂在这吧。。。。。。

posted @ 2020-12-02 23:12  empty_thought  阅读(168)  评论(0)    收藏  举报