数据结构C语言版,两个题目求大神解答。

1、将字符串s=”***abcde**defg**1234***”中所有’*’移动到最
后:s=”abcdedefg1234**********”
typedef struct node
{ char data[50];
int length;
}seqstring;
2、计算二叉树中第n(n>1)层有多少个结点
结构体定义:typedef struct node
{int data;
struct node *lchild,*rchild;
}btnode;
例:第5层有4个结点

#define NULL 0

typedef struct node{
char data[50];
int length;
}seqstring;

void fun(seqstring* s) {
int i = 0, j = 0;
for (j = 0; j < s->length; j++) {
if (s->data[j] != '*') {
s->data[i] = s->data[j];
i++;
}
}
while (i < s->length) {
s->data[i] = '*';
i++;
}
}

typedef struct node {
int data;
struct node *lchild, *rchild;
}btnode;

int fun2(btnode* n, int level) {
if (n == NULL) return 0;
if (level == 0) return 1;
return fun2(n->lchild, level - 1) + fun2(n->rchild, level - 1);
}

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答
大家正在搜