国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 沾益县| 商都县| 思茅市| 安平县| 长沙县| 武平县| 丁青县| 始兴县| 左贡县| 香河县| 双鸭山市| 太湖县| 江门市| 大田县| 鹤岗市| 杭锦后旗| 建昌县| 丰原市| 徐州市| 合肥市| 灵武市| 赣州市| 东港市| 淳化县| 集安市| 东城区| 崇明县| 凤阳县| 铁力市| 塘沽区| 民和| 海安县| 乐平市| 定远县| 晴隆县| 嵊州市| 襄樊市| 会东县| 青海省| 红桥区| 红河县|