#用链表实现队列
class student:
def __init__(self):
self.score=0
self.next=None
front=student()
rear=student()
front=None
rear=None
choice=''
while(choice!='e'):
choice=input("a:插入,b:删除 e:退出 : ")
if(choice=='a'):
newdata = student()
newdata.score =int(input("输入要插入的分数值:"))
if rear==None:
front=newdata
else:
rear.next=newdata
rear=newdata
newdata.next=None
if(choice=='b'):
if front==None:
print("队列已空")
else:
print("%d 已没"%front.score)
front=front.next
if (choice == 'e'):
break
ptr=front
if ptr==None:
print("队列yikong")
else:
while ptr!=None:
print("score:%d"%ptr.score)
ptr=ptr.next
python 数据结构 用链表实现队列
最新推荐文章于 2022-02-17 13:03:28 发布