#模拟栈结构
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语言基础")