日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Day09-递归

發布時間:2023/12/20 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Day09-递归 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#模擬棧結構 stack = [] #壓棧(想棧里存數據) stack.append("A") print(stack) stack.append("B") print(stack) stack.append("C") print(stack)#出棧(在棧里取數據) res = stack.pop() print("res= ",res) print(stack) res = stack.pop() print("res2= ",res) print(stack) res = stack.pop() print("res3= ",res) print(stack)import collections#創建一個隊列 queue = collections.deque() print(queue)#進隊(存數據) queue.append("A") print(queue) queue.append("B") print(queue) queue.append("C") print(queue)#出隊(取數據) res1 = queue.popleft() print("res1 = ",res1) print(queue)import osdef getAllDir(path,sp=""):sp +=" "# 得到當前目錄下所有文件fileList = os.listdir(path)#處理每一個文件for fileName in fileList:#path\fileName#判斷是否是路徑(用絕對路徑)fileAbsPath = os.path.join(path,fileName)if os.path.isdir(fileAbsPath):print(sp+"目錄:",fileName)#遞歸調用getAllDir(fileAbsPath,sp)else:print(sp+"普通文件:",fileName)getAllDir(r"D:\xiazaipan\第1章 Python語言基礎\第1章 Python語言基礎")import os def getAllDirDE(path):stack =[]stack.append(path)#處理棧,當棧為空的時候結束循環while len(stack)!=0:#從棧里取出數據dirPath = stack.pop()fileList = os.listdir(dirPath)#處理每一個文件,如果是普通文件則打印出來,如果是目錄則將該目錄地址壓棧for fileName in fileList:fileAbspath = os.path.join(dirPath,fileName)if os.path.isdir(fileAbspath):#如果是目錄就壓棧stack.append(fileAbspath)print("目錄:",fileName)else:#打印普通文件print("普通文件:"+fileName)getAllDirDE(r"D:\xiazaipan\第1章 Python語言基礎\第1章 Python語言基礎")import os import collections def getAllDirQU(path):queue = collections.deque()#進隊queue.append(path)while len(queue)!=0:#出隊數據dirPath = queue.popleft()#找出所有文件fileList = os.listdir(dirPath)for fileName in fileList:#絕對路徑fileAbsPath = os.path.join(dirPath,fileName)#判斷是否是目錄,是目錄進隊,不是打印if os.path.isdir(fileAbsPath):print("目錄"+fileName)queue.append(fileAbsPath)else:print("普通文件"+fileName)getAllDirQU(r"D:\xiazaipan\第1章 Python語言基礎\第1章 Python語言基礎")

?

總結

以上是生活随笔為你收集整理的Day09-递归的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。