严蔚敏 数据结构习题6.47
来源:互联网 发布:法兰克机器人编程 编辑:程序博客网 时间:2024/05/16 07:08
编写按层次顺序(同一层自左至右)遍历二叉树的算法
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <malloc.h>#include <queue>using namespace std;typedef struct tnode{ int data; struct tnode *lchild,*rchild;}*bitree;int creattree(bitree &bt){ char ch; scanf("%c",&ch); getchar(); if(ch=='#')bt=NULL; else { bt=(tnode*)malloc(sizeof(tnode)); bt->data=ch; printf("输入%c的左子节点:", ch); creattree(bt->lchild); printf("输入%c的右子节点:", ch); creattree(bt->rchild); } return 1;}void visit(bitree p){ printf("%c ",p->data);}void levelserach(bitree bt){ queue<struct tnode*>que; bitree p; if(bt)que.push(bt); while(!que.empty()) { p=que.front(); que.pop(); visit(p); if(p->lchild)que.push(p->lchild); if(p->rchild)que.push(p->rchild); }}int main(){ bitree bt; bt=(tnode*)malloc(sizeof(tnode)); printf("输入根节点:"); creattree(bt); printf("按层次顺序遍历:\n"); levelserach(bt); return 0;}
0 0
- 严蔚敏 数据结构习题6.47
- 严蔚敏数据结构习题3.17
- 严蔚敏数据结构习题3.31
- 严蔚敏数据结构习题3.32
- 严蔚敏 数据结构习题 6.41
- 严蔚敏 数据结构习题 6.49
- 严蔚敏 数据结构习题 6.52
- 严蔚敏 数据结构习题6.62
- 数据结构习题
- 数据结构习题
- 数据结构习题
- 数据结构习题
- 严蔚敏 数据结构习题 C语言 4.10~4.13
- 数据结构习题与解析
- Linux下:数据结构习题
- 数据结构习题答案-第一章
- 数据结构习题1
- 数据结构---习题(C++)
- Delphi中如何调用Excel VBA
- JVM内存回收策略介绍
- Socket Programming
- cygwin跨平台移植开发系列3--GCC+VC联合使用
- 程序员常去的14个顶级开发社区
- 严蔚敏 数据结构习题6.47
- 【解决方案】Cmder v1.2 解决 “profile.ps1”和"Join-Path"方法
- CSS入门(3)-background:transparent的作用
- fastJson解析
- poj 1061/2142 扩展的欧几里得(青蛙的约会/砝码称重)
- Codeforces Round #333 (Div. 2)C. The Two Routes(最短路)
- 黑马程序员 JavaSE-09 Map
- [LeetCode261] Graph Valid Tree
- easyUI级联