国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

層次遍歷二叉樹,并輸出節點所在的行數

2019-11-08 02:57:03
字體:
來源:轉載
供稿:網友
//層次遍歷二叉樹,并輸出節點所在的行數public static void main(String[] args) {TwoTree root = new TwoTree(1);root.left = new TwoTree(2);root.left.left = new TwoTree(3);root.left.left.left = new TwoTree(4);root.right = new TwoTree(5);PRint(root);}public static void print(TwoTree root){Queue<TwoTree> queue = new LinkedList<TwoTree>();TwoTree last = root;TwoTree nlast = root;int num = 1;TwoTree point = root;queue.add(point);while(!queue.isEmpty()){point = queue.poll();System.out.println("行數:"+num+"---"+point.value);if(point.left!=null){queue.add(point.left);nlast = point.left;}if(point.right!=null){queue.add(point.right);nlast = point.right;}if(last == point){last = nlast;num++;}}}

public class TwoTree {TwoTree left;TwoTree right;int value;public TwoTree(int a){value = a;left = null;right = null;}}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁陵县| 水城县| 洛阳市| 乐亭县| 鄄城县| 龙井市| 行唐县| 贵德县| 保康县| 谢通门县| 申扎县| 安塞县| 泰兴市| 宝兴县| 福安市| 贞丰县| 班玛县| 云梦县| 吉隆县| 大方县| 驻马店市| 余庆县| 淮安市| 冀州市| 寻甸| 嘉禾县| 都昌县| 加查县| 仪陇县| 鱼台县| 扶绥县| 镇原县| 永年县| 满洲里市| 星子县| 盐边县| 偏关县| 哈密市| 志丹县| 金溪县| 昭平县|