operate_stack.h

来自「数据结构课程设计报告,虽然好多地方都有」· C头文件 代码 · 共 71 行

H
71
字号

#define MAXSIZE 50
/*==================================*/
/*结构体定义                        */
/*==================================*/
typedef struct{
	int data[MAXSIZE];
	int top;
}Stack;


/*==================================*/
/*建立空的顺序栈                    */
/*==================================*/
void Empty_Stack(Stack *S)
{
	S->top=-1;   //置空
}

/*==================================*/
/*输入顺序栈                        */
/*==================================*/
void Insert_Stack(Stack *S, int scan_max)
{
	int scan_x, i;
	for(i=0; i < scan_max; i++)
	{
		printf("元素%d=",i+1);
		scanf("%d",&scan_x);
		/*插入新元素             */
		S->top++;
		S->data[S->top]=scan_x;
	}
}


/*==================================*/
/*显示顺序栈                        */
/*==================================*/
void Print_Stack(Stack S)
{
	int i;
	if(S.top==-1)
		printf("空栈\n");
	else
	{
		for(i=0; i<=S.top; i++)
		{
			printf("%d",S.data[i]);
		}
	}
	printf("\n");
}

	
/*==================================*/
/*出栈                              */
/*==================================*/
void Push_Stack(Stack *S, int *temp)
{
	if(S->top==-1)
		printf("空栈\n");
	else
	{
		/*取元素,修改TOP           */
		*temp=S->data[S->top];
		S->top--;
	}
}

	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?