x # 数据结构1. 队列:先进来的先出去,先进先出2. 栈:先进来的后出来,先进后出'''使用列表的内置方法实现以上两种数据结构'''
#队
my_friends = ['tony', 'jason', 'tom', 4, 5, 6, 7, 88888]
cmd="w"
while cmd != '0' :
print("输入指令:(1进入,2出,0为退出)")
cmd = input().strip()
if cmd== '1':
print("输入添加内容")
my_friends.append(input())
print(my_friends)
elif cmd== '2':
aa = my_friends.pop(0)
print(aa)
print(my_friends)
#print("成功,再来")
elif cmd == '0':
break
else:
print("错误,重来")
#栈
my_friends = ['tony', 'jason', 'tom', 4, 5, 6, 7, 88888]
cmd="w"
while cmd != '0' :
print("输入指令:(1进入,2出,0为退出)")
cmd = input().strip()
if cmd== '1':
print("输入添加内容")
my_friends.append(input())
print(my_friends)
elif cmd== '2':
aa = my_friends.pop()
print(aa)
print(my_friends)
#print("成功,再来")
elif cmd == '0':
break
else:
print("错误,重来")
网友评论