堆栈数据结构的C语言实现
来源:互联网 发布:徐甜甜 知乎 编辑:程序博客网 时间:2024/05/22 17:32
#defineOVERFLOW -1
#define ERROR -2
#define OK 1
#define NULL 0
#define STACK_INT_SIZE 100
#define STACKINCREMENT 10
#include <stdio.h>
typedef struct{
char *base;
char *top;
int stacksize;
}SqStack;
#define OK 1
#define NULL 0
#define STACK_INT_SIZE 100
#define STACKINCREMENT 10
#include <stdio.h>
typedef struct{
char *base;
char *top;
int stacksize;
}SqStack;
int CreatStack(SqStack *S)
{
(*S).base=(char*)malloc(STACK_INT_SIZE*sizeof(char));
if(!(*S).base) return ERROR;
(*S).top=(*S).base;
(*S).stacksize=STACK_INT_SIZE;
return OK;
}
{
}
int StackLength(SqStack S)
{SqStack p;
int length=0;
p=S;
while(p.base!=p.top)
{p.top--;
length++;
}
return length;
}
{SqStack p;
}
int GetTop(SqStack S,char *e)
{if(S.base==S.top) return ERROR;
*e=*(S.top-1);
return OK;
}
{if(S.base==S.top)
}
int Push(SqStack *S,char e)
{
if((*S).top-(*S).base>=(*S).stacksize){
(*S).base=(char*)realloc((*S).base,((*S).stacksize+STACKINCREMENT)*sizeof(char));
if((*S).base) exit(OVERFLOW);
(*S).top=(*S).base+(*S).stacksize;
(*S).stacksize+=STACKINCREMENT;
}
*((*S).top)++=e;
return OK;
}
{
}
int Pop(SqStack *S,char *e)
{if((*S).top==(*S).base)
returnERROR;
*e=*--(*S).top;
return OK;
}
{if((*S).top==(*S).base)
}
int DestroyStack(SqStack *S)
{char *p;
while((*S).top!=(*S).base)
{p=(*S).top;
--(*S).top;
free(p);
}
return OK;
}
{char *p;
}
int ClearStack(SqStack *S)
{int length,n;
if(S->base==S->top)return OK;
else
{while(S->base!=S->top)
*(--S->top)=NULL;
}
return OK;
}
{int length,n;
}
int Print(SqStack *S)
{
char *p;
for(p=S->top-1;p>=S->base;p--)
printf("%c",*p);
printf("\n");
return OK;
}
{
}
int StackEmpty(SqStack S)
{if(S.top==S.base)
return OK;
else
return NULL;
}
{if(S.top==S.base)
}
main()
{SqStack *stack,*stack1,*stack2;
char *c,e;
stack=(SqStack*)malloc(sizeof(SqStack));
stack1=(SqStack*)malloc(sizeof(SqStack));
stack2=(SqStack*)malloc(sizeof(SqStack));
c=(char *)malloc(sizeof(char));
clrscr();
CreatStack(stack);
CreatStack(stack1);
CreatStack(stack2);
printf("Have created a stack,the length ofit is %d\n",StackLength(*stack));
if(!StackEmpty(*stack))
printf("Stack is not empty!\n");
else
printf("Stack is empty!\n");
printf("Please input chars(End with'!'):\n");
{SqStack *stack,*stack1,*stack2;
}
0 0
- C语言实现堆栈(栈)的数据结构
- 堆栈数据结构的C语言实现
- 堆栈数据结构的C语言实现
- 堆栈的c 语言实现
- 堆栈的C语言实现
- C语言 数据结构 堆栈的压栈出栈实例
- C语言数据结构之堆栈
- 数据结构C语言实现系列——链式堆栈
- C语言实现堆栈
- C语言实现堆栈
- 堆栈的实现(c语言)
- 堆栈数据结构的实现~
- 数据结构--堆栈的实现
- C语言的堆栈
- c语言的堆栈
- 数据结构:泛型堆栈的实现(C++)
- 数据结构C语言利用堆栈表达式求值
- 堆栈的C实现
- s3c2410时钟信号:FCLK、HCLK和PCL…
- s3c2410时钟信号:FCLK、HCLK和PCL…
- [转]枚举类型和枚举变量
- [转]枚举类型和枚举变量
- 堆栈数据结构的C语言实现
- 堆栈数据结构的C语言实现
- linux之TQ2440通过nfs挂载根文件系…
- linux之TQ2440通过nfs挂载根文件系…
- 改变TQ2440默认作为终端的串…
- 改变TQ2440默认作为终端的串…
- 逻辑地址、线性地址、物理地址和虚…
- 逻辑地址、线性地址、物理地址和虚…
- 预处理,编译, 优化, 汇编…
- 预处理,编译, 优化, 汇编…