参数问题

xiangmengxia xiangmengxia 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
有人能清楚的说一下参数带*和不带*,参数带&和不带&,参数带&和参数带*的区别吗?经常在书中看到这个,不是很清楚。
刚做一个二叉树的非递归遍历问题,我感觉是参数除了问题,就是不知道处在哪里,有空的帮忙看一下,谢谢!
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#define OK 1
#define ERROR 0

typedef struct BiTNode{
char data;
BiTNode *rchild,*lchild;
}BiTNode,*BiTree;

typedef struct{
BiTNode *top,*base;
int stacksize;
}SqStack;

void visit(BiTNode a){
printf("%c ",a.data);
}

int InitStack(SqStack &S){
S.base=(BiTree)malloc(sizeof(BiTNode)*100);
if(!S.base)
return ERROR;
S.top=S.base;
S.stacksize=100;
return OK;
}

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

int Push(SqStack &S,BiTNode tree){
if(S.stacksize<=S.top-S.base){
S.base=(BiTNode*)realloc(S.base,(S.stacksize+10)*sizeof(BiTNode));
if(!S.base)return 0;
S.top=S.base+S.stacksize;
S.stacksize+=10;
}
*S.top++=tree;
return 1;
}

int Pop(SqStack &S){
if(S.top==S.base)
return 0;
S.top--;
return 1;
}

void preOrder(BiTree tree){

SqStack S;
InitStack(S);

while(tree->data!='#'||!SqStackEmpty(S)){
while(tree->data!='#'){
visit(*tree);
Push(S,*tree);
tree=tree->lchild;
}
if(!SqStackEmpty(S)){
Pop(S);
tree=tree->rchild;
}
}
}

int main(){
BiTree tree;
printf("请输入一棵树(先序,输入#表示为空):\n");
scanf("%s",&tree);
preOrder(tree);
return OK;
}
...全文
评论 6
收藏 已收藏
分享
返回顶部
xiangmengxia
C语言 70,039 成员 243,237 内容