数据结构之链式栈
来源:互联网 发布:青果软件掌上校园 编辑:程序博客网 时间:2024/05/14 09:03
#include<stdio.h>
#include<string.h>
#include<string>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
#define OK 1
#define ERROR 0
typedef int status;
typedef int Elemtype;
typedef struct stackNode
{
Elemtype data;
struct stackNode *next;
} stackNode,*linkNode;
typedef struct linkStack
{
linkNode top;
int stacksize;
} linkStack;
status push(linkStack &s,Elemtype e)
{
linkNode p,q;
p=(stackNode *)malloc(sizeof(stackNode));
if(p==NULL)return ERROR;
p->data=e;
p->next=s->top;
s->top=p;
s->stacksize++;
return OK;
}
status pop(linkStack &s)
{
linkStack p;
p=s->top;
s->top=p->top;
free(p);
s.stacksize--;
return OK;
}
status traverse(linkStack s){
while(s->top!=NULL){
printf("%d ",s.top->data);
s.top=s->top;
}
return OK;
}
#include<string.h>
#include<string>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
#define OK 1
#define ERROR 0
typedef int status;
typedef int Elemtype;
typedef struct stackNode
{
Elemtype data;
struct stackNode *next;
} stackNode,*linkNode;
typedef struct linkStack
{
linkNode top;
int stacksize;
} linkStack;
status push(linkStack &s,Elemtype e)
{
linkNode p,q;
p=(stackNode *)malloc(sizeof(stackNode));
if(p==NULL)return ERROR;
p->data=e;
p->next=s->top;
s->top=p;
s->stacksize++;
return OK;
}
status pop(linkStack &s)
{
linkStack p;
p=s->top;
s->top=p->top;
free(p);
s.stacksize--;
return OK;
}
status traverse(linkStack s){
while(s->top!=NULL){
printf("%d ",s.top->data);
s.top=s->top;
}
return OK;
}
阅读全文
0 1
- 数据结构之链式栈
- 数据结构之链式栈
- 数据结构之链式栈
- Java数据结构之链式栈
- 常用数据结构之链式存储的栈
- java 数据结构之 链式存储结构 栈
- C++数据结构之Linked Stack(链式栈)
- 数据结构之栈的链式存储结构
- 数据结构之链式栈的构建
- 数据结构之线性结构---栈 链式储存
- 数据结构——栈之链式存储
- 数据结构之链式队列
- 数据结构之链式表
- 数据结构之链式队列
- 数据结构之链式队列
- 数据结构之链式队列
- 数据结构 链式栈
- 【数据结构】链式栈 Linked_stack
- 创建视图时报 insufficient privileges 错误怎么办
- oracle定时器
- Qt 学习之路 2(47):视图选择
- Javascript 面向对象编程(一):封装
- stm32在rt-thread上的PWR(电源管理)
- 数据结构之链式栈
- 分页用实体类
- PHP 函数漏洞总结
- postgres数据库导入导出
- SpirngMVC 提交表单数据到Controller时报400错误(The request sent by the client was syntactically incorrect.)
- A problem occurred configuring project ':AndroidLib'. > You have not accepted the license agreements
- STM32定时器产生PWM--呼吸灯
- 星号变量的特殊用法
- 大数据时代下的隐私保护