⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stack.h

📁 数据结构实验程序 线性表 栈和队列 二叉树 图 查找 内部排序
💻 H
字号:
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>



#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10

typedef struct BiTNode{
	char data;
	struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;


struct SqStack{
	BiTree *base;
    BiTree *top;
	int stacksize;
};

void InitStack(struct SqStack *S)
{S->base=(BiTree*)malloc(STACK_INIT_SIZE*sizeof(BiTree));
if(!S->base)exit(0);
S->top=S->base;
S->stacksize=STACK_INIT_SIZE;
}

void Push(struct SqStack* S,BiTree e)
{if(S->top-S->base>=S->stacksize)
{S->base=(BiTree*)realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof(BiTree));
if(!S->base)exit(0);
S->top=S->base+S->stacksize;
S->stacksize+=STACKINCREMENT;}
*S->top++=e;
}

BiTree Pop(struct SqStack *S,BiTree e)
{
if(S->top-S->base>0)
e=*--S->top;
return e;
}



BiTree Top(struct SqStack *S,BiTree e)
{
if(S->top-S->base>0)
e=*(S->top-1);
return e;
}



int StackEmpty(struct SqStack *S)
{if(S->top-S->base==0)return 1;
else return 0;
}

⌨️ 快捷键说明

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