好文档 - 专业文书写作范文服务资料分享网站

数据结构程序图片例子

天下 分享 时间: 加入收藏 我要投稿 点赞

1. 数制转换(十进制转换为八进制)

#include #include

#define STACK_INIT_SIZE 100 #define STACKINCREMENT 10 typedef int Status,SElemType; typedef struct{ SElemType *base; SElemType *top; int stacksize; }SqStack;

Status InitStack(SqStack &S); Status StackEmpty(SqStack S);

Status Push(SqStack &S,SElemType e); Status Pop(SqStack &S,SElemType &e); Status InitStack(SqStack &S)

{S.base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType)); if(!S.base)exit (1);//存储分配失败 S.top=S.base;

S.stacksize=STACK_INIT_SIZE; return 0; }

Status Push(SqStack &S,SElemType e) {if(S.top-S.base>=S.stacksize)

{S.base=(SElemType *)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(SElemType)); if(!S.base) exit(1);//存储分配失败 S.top=S.base+S.stacksize;

S.stacksize+= STACKINCREMENT; }

*S.top++=e;

return 0; }

Status Pop(SqStack &S,SElemType &e)//若栈不空,则删除S的栈顶元素,用e返回;否则返回1

{if(S.top==S.base) return 1; e=*--S.top; return 0; }

Status StackEmpty(SqStack S) {if(S.top==S.base) return 1; else return 0; }

Status ClearStack(SqStack &S) {S.top=0; }

int main()//对于输入的任意一个非负十进制整数,打印输出与其等值的八进制数 {int n,e=0; SqStack s;

InitStack(s);//构造空栈

printf(\输入一个非负十进制整数:\ scanf(\

printf(\输出它所对应的八进制数:\ while(n)

{ Push(s,n%8); n=n/8; }

while(!StackEmpty(s)) {Pop(s,e);

printf(\ }

return 0; }

2. 括号匹配

3.顺序表逆置

4.稀疏矩阵转置

数据结构程序图片例子

1.数制转换(十进制转换为八进制)#include#include#defineSTACK_INIT_SIZE100#defineSTACKINCREMENT10typedefintStatus,SElemType;typedefstruct{SElemType*base;
推荐度:
点击下载文档文档为doc格式
1p84w8yz956trx01723y3gzju6vsnw00dlh
领取福利

微信扫码领取福利

微信扫码分享