duizhan.h
来自「八皇后问题求解」· C头文件 代码 · 共 43 行
H
43 行
//stack.h 支持栈操作
#define initsize 100
#define increment 20
#include<malloc.h>
#include<stdio.h>
#include<iostream.h>
struct store{
int *base;
int *top;
int storesize;
};
void initstack(struct store &s)
{
s.base=(int *)malloc(initsize *sizeof(int));
if(!s.base){
printf("Malloc Fali!\n");
initstack(s);
};
s.top=s.base;
s.storesize=initsize ;
};
void push(struct store &s,int e){
if(s.top-s.base>=s.storesize){
s.base=(int *)realloc(s.base,(s.storesize+increment)*sizeof(int));
if(!s.base){
printf("Realloc Fail!\n");
push(s,e);
};
s.top=s.base+s.storesize;
s.storesize+=increment;
}
*s.top++=e;
};
void pop(struct store &s){
if(s.top!=s.base)
--s.top;
else
printf("Stack Empty!\n");
};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?