简易的顺序栈
来源:互联网 发布:lol韩服网络错误 编辑:程序博客网 时间:2024/06/06 07:15
/*****************************************************
copyright (C), 2014-2015, Lighting Studio. Co., Ltd.
File name:
Author:fhb Version:0.1 Date:
Description:
Funcion List:
*****************************************************/
#include <stdio.h>
#include <stdlib.h>
#define max 10
typedef struct stack
{
int stack[max];
int top;
}Stack;
enum return_result {full_ok,full_no,empty_ok,empty_no,
push_ok,push_no,pop_ok,pop_no=-1};
void creat_stack(Stack ** stack)
{
(*stack)=(Stack*)malloc(sizeof(Stack));
if((*stack) == NULL)
{
printf("creat error!\n");
exit(-1);
}
}
void init_stack(Stack ** stack)
{
(*stack)->top = -1;
}
int is_full(Stack ** stack)
{
if((*stack)->top >= max)
{
return full_ok;
}
return full_no;
}
int push_stack(Stack ** stack,int num)
{
if(is_full(stack) == full_ok)
{
printf("the stack is full!\n");
return push_ok;
}
(*stack)->top++;
(*stack)->stack[(*stack)->top] = num;
return push_no;
}
int is_empty(Stack ** stack)
{
if((*stack)->top <= -1)
{
return empty_ok;
}
return empty_no;
}
int pop_stack(Stack ** stack)
{
if(is_empty(stack) == empty_ok)
{
printf("the stack is empty!\n");
return pop_no;
}
return ((*stack)->stack[((*stack)->top)--]);
}
int main()
{
Stack * stack;
int i;
int ret;
creat_stack(&stack);
init_stack(&stack);
for(i = 0;i < max;i++)
{
push_stack(&stack,i);
//printf("push success!\n");
}
for(i = 0;i < max;i++)
{
ret = pop_stack(&stack);
if(ret == pop_no)
{
break;
}
printf("stack[%d]=%d\n",i,ret);
}
return 0;
}
copyright (C), 2014-2015, Lighting Studio. Co., Ltd.
File name:
Author:fhb Version:0.1 Date:
Description:
Funcion List:
*****************************************************/
#include <stdio.h>
#include <stdlib.h>
#define max 10
typedef struct stack
{
int stack[max];
int top;
}Stack;
enum return_result {full_ok,full_no,empty_ok,empty_no,
push_ok,push_no,pop_ok,pop_no=-1};
void creat_stack(Stack ** stack)
{
(*stack)=(Stack*)malloc(sizeof(Stack));
if((*stack) == NULL)
{
printf("creat error!\n");
exit(-1);
}
}
void init_stack(Stack ** stack)
{
(*stack)->top = -1;
}
int is_full(Stack ** stack)
{
if((*stack)->top >= max)
{
return full_ok;
}
return full_no;
}
int push_stack(Stack ** stack,int num)
{
if(is_full(stack) == full_ok)
{
printf("the stack is full!\n");
return push_ok;
}
(*stack)->top++;
(*stack)->stack[(*stack)->top] = num;
return push_no;
}
int is_empty(Stack ** stack)
{
if((*stack)->top <= -1)
{
return empty_ok;
}
return empty_no;
}
int pop_stack(Stack ** stack)
{
if(is_empty(stack) == empty_ok)
{
printf("the stack is empty!\n");
return pop_no;
}
return ((*stack)->stack[((*stack)->top)--]);
}
int main()
{
Stack * stack;
int i;
int ret;
creat_stack(&stack);
init_stack(&stack);
for(i = 0;i < max;i++)
{
push_stack(&stack,i);
//printf("push success!\n");
}
for(i = 0;i < max;i++)
{
ret = pop_stack(&stack);
if(ret == pop_no)
{
break;
}
printf("stack[%d]=%d\n",i,ret);
}
return 0;
}
0 0
- 简易的顺序栈
- (学习java)利用顺序栈简易计算器的编写
- 灰常简易的顺序队列
- 简易静态顺序表
- 用顺序表实现的简易通讯录(第一版)
- 动态顺序表部分接口的简易实现
- (学习java)顺序循环队列的简易实现
- 简易栈的实现
- 简易版C++顺序表
- 栈完成简易的计算器
- 线性表(顺序存储)结构与功能的简易实现
- sql语句执行顺序简易理解
- 栈的简易应用,愚人节的礼物
- 【顺序栈作业】顺序栈的实现
- 顺序栈:栈的顺序存储结构
- 堆栈的顺序存储---顺序栈
- 简易计算器(栈的应用)
- 栈的顺序实现
- ubuntu上安装mysql
- NSAttributedString描述和应用
- Android 打开各种文件的方法
- 数据表与简单Java类映射-依靠代码链
- vb 引用adodb问题
- 简易的顺序栈
- PHP学习(1)--数据库的连接
- codevs 2822 爱在心中(Tarjan)
- 如何保证Service不被杀死一直运行
- The resource could not be loaded because the App Transport Security policy requires the use of a sec
- 机器学习基石(林轩田)——笔记1
- 大话-从市场需求->芯片设计->SDK开发->Turnkey方案->定制化产品 --- SDK开发(三) 即将开启大话专题 ISP篇,希望喜欢大话技术的读者加群147565042,我们一起“吹”集结号
- 灰常简易的顺序队列
- 小波的秘密10_图像处理应用:图像增强