太冷了今天,所以还是留在宿舍学习了。
今天的计划:
英1阅读数学大题肖八一份1000题错题整理- 看英作文
- 有空的话背一下专业课概念
今日废话:
今天尝试去登录了之前的微博,可是并不能登录上去,因为之前的手机号已经不用了。
然后尝试进行申诉,可能过了2个多小时吧,客服说不通过。
其实我恨不明白,我账号写的就是我真名,我还提交了手持身份证照片,我还知道账号的正确密码,我还能进行邮箱验证,我tm为什么还不能证明我是我自己。
微博,不仅仅是互联网的垃圾桶,它本身就很垃圾。
很气,我到底应该怎么证明我是我自己。
哦,顺带给这个博客增加了2个主题,怎么说呢感觉并不是很好看但是比较有新鲜感。 好了新鲜感过了,果然还是这个最简洁的比较好看。
孩子兄弟树这玩意儿考的是真的多,整了个真题写了一下。
需要统计一共有几代人,然后输出最后一代人。
代码如下:
#include <stdio.h>
#include <string.h>
typedef struct CSNode{
char name[50]; // 姓名
struct CSNode *firstchild, *nextsibling;
// 图方便写的构造函数
CSNode(char* name){
strcpy(this->name, name);
this->firstchild = NULL;
this->nextsibling = NULL;
}
}CSNode, *CSTree;
void LevelOrderTraversal(CSTree T){
// 统计有几代人和最后一代人的名字
int _count = 0;
CSTree CStack[100];
int top = 0;
int last = 0; // 指向这一代最后一个孩子
int width = 0; // 这一代人的宽度,一共有多少人
int lastwidth = 0;
// 用循环队列来实现
CSTree CQueue[100];
int queuelength = 100;
int rear = 0;
int front = 0;
// 临时变量
CSTree tmp,tmp0;
// 将第一个元素入队
CQueue[rear] = T;
rear = (rear+1)%queuelength;
// 层次遍历
while(rear != front){
// 将队头元素出队 并 入栈
tmp = CQueue[front];
tmp0 = CQueue[front];
front = (front + 1)% queuelength;
CStack[top] = tmp; // 入栈
top ++;
// 判断是否有孩子
if (tmp->firstchild != NULL){
// 将第一个孩子入队
CQueue[rear] = tmp->firstchild;
rear = (rear + 1)% queuelength;
// 将兄弟入队
tmp = tmp->firstchild;
while(tmp->nextsibling != NULL){
CQueue[rear] = tmp->nextsibling;
rear = (rear+1)%queuelength;
tmp = tmp->nextsibling;
}
}
// 判断是不是这一代最后一个孩子
if (last == front-1){
_count += 1;
last = rear-1;
lastwidth = width;
width = rear - front; // 最后一行的width=0,所以用lastwidth来保存前一行的
printf("> last: %d , width: %d \n", last, width);
}
// 输出当前元素
printf("%s \n", tmp0->name);
}
printf("一共有%d代人\n", _count);
while (lastwidth != 0){
printf("%s \n", CStack[--top]);
lastwidth --;
}
}
int main(){
CSTree T = new CSNode("Sam");
T->firstchild = new CSNode("Ad");
T->firstchild->nextsibling = new CSNode("Pig");
T->firstchild->firstchild = new CSNode("Gird");
T->firstchild->firstchild->nextsibling = new CSNode("dig");
T->firstchild->firstchild->nextsibling->nextsibling = new CSNode("Ma");
T->firstchild->firstchild->nextsibling->firstchild = new CSNode("Dao");
T->firstchild->nextsibling->firstchild = new CSNode("Lin");
T->firstchild->nextsibling->firstchild->firstchild = new CSNode("Xia");
T->firstchild->nextsibling->firstchild->firstchild->nextsibling = new CSNode("Pu");
// 层次遍历并输出最后一代人的人数和成员名字
LevelOrderTraversal(T);
return 0;
}
写代码的速度明显不够啊这考场上感觉时间还是挺紧的,还是得多写找找感觉。
0 Comments latest
No comments.