美文网首页
栈 队列 递归应用,循环处理,如目录遍历

栈 队列 递归应用,循环处理,如目录遍历

作者: 背起我的破书包 | 来源:发表于2018-03-25 22:19 被阅读0次

# 递归遍历"""

cur_path = r"C:\Users\Nic\Desktop\2018python\case"

# def find_file(path,sp=""):

#    all_file = os.listdir(path)

#    sp+="    "

#    for file_name in all_file:

#        abs_filpath=os.path.join(path, file_name)       

#        if os.path.isdir(abs_filpath):

#            find_file(abs_filpath,sp)

#            print(sp +"目录:", file_name)

#        else:

#            print(sp + "普通文件:", file_name)

# find_file(cur_path)

"""栈模拟(深度遍历)"""       

# def  getallRe(path):

#    stack = []

#    stack.append(path)

#    while len(stack) !=0:

#        dirPath = stack.pop()

#        fileList = os.listdir(dirPath)

#        for file_name in fileList:           

#            fileabsPath = os.path.join(dirPath, file_name)

#            if os.path.isdir(fileabsPath):

#                print("目录: ",file_name)

#                stack.append(filePath)

#            else:

#                print("普通文件: ", file_name)

# getallRe(cur_path)

"""广度遍历,队列,同级目录处理"""

# def getfielQqe(path):

#    queue = collections.deque()

#    queue.append(path)

#    while len(queue) !=0:

#        dirpath = queue.popleft()

#        filelist = os.listdir(dirpath)

#        for file_name in filelist:           

#            fileabsPath = os.path.join(dirpath, file_name)

#            if os.path.isdir(fileabsPath):

#                print("目录: ",file_name)

#                queue.append(fileabsPath)

#            else:

#                print("普通文件: ", file_name)

# getfielQqe(cur_path)

相关文章

网友评论

      本文标题:栈 队列 递归应用,循环处理,如目录遍历

      本文链接:https://www.haomeiwen.com/subject/luykcftx.html