#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018-05-25 10:16
# @Author  : xxd
# @File    : test.py

class Node:

    def __init__(self,data,left=None,right=None):
        self.data=data
        self.left=left
        self.right=right
def BFS(Node):
    if Node == None:
        return
    quene = []
    quene.append(Node)
    while quene:
        Node = quene.pop(0)
        print(Node.data)
        if Node.left:
            quene.append(Node.left)
        if Node.right:
            quene.append(Node.right)
if __name__ == '__main__':
 t=Node(1,Node(2),Node(3))
 BFS(t)

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐