#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
typedef struct node{//孩子结点
char data;
struct node*firstc;
struct node*nextx;
}node;
node* initc(node* t){
char d;
cin>>d;
if(d=='#'){
t=NULL;
}
else{
t=(node*)malloc(sizeof(node));
t->data=d;
t->firstc=NULL;
t->nextx=NULL;
printf("%c 的第一个孩子:",t->data);
t->firstc=initc(t->firstc);
printf("%c 的下个兄弟:",t->data);
t->nextx=initc(t->nextx);
}
return t;
}
void initroot(node* &tree){
tree=(node*)malloc(sizeof(node));
tree->data=' ';
tree->firstc=NULL;
tree->nextx=NULL;
printf("please input root data:");
tree->firstc=initc(NULL);
}
void print(node* t){
if(t!=NULL){
printf("%c ",t->data);
print(t->firstc);
print(t->nextx);
}
}
int main(){
node*t=NULL;
initroot(t);
print(t->firstc);
}
c语言数据结构---树的孩子兄弟表示法
最新推荐文章于 2024-07-08 21:10:38 发布