data=[[1001,32367],[1002,24338],[1003,27556],[1007,31299],\
[1012,42660],[1018,44145],[1018,44145],[1043,52182],\
[1031,32769],[1037,21100],[1041,32196],[1046,25776]]
namedata=['allen','scott','marry','john','mark','ricky',\
'lisa','jasica','hanson','amy','bob','jack']
class employee:
def __init__(self):
self.name=''
self.no=0
self.salry=0
self.next=None
head=employee()
head.name=namedata[0]
head.no=data[0][0]
head.salry=data[0][1]
head.next=None
ptr=head
for i in range(1,12):
newnode=employee()
newnode.name=namedata[i]
newnode.no=data[i][0]
newnode.salry=data[i][1]
newnode.next=None
ptr.next=newnode
ptr=ptr.next
ptr=head
while ptr!=None:
print('\t[%2d]\t[%-7s]\t[%3d]' % (ptr.no, ptr.name, ptr.salry))
ptr=ptr.next
print('**************************************************************')
ptr=head
before=None
while ptr!=None:
last=before
before=ptr
ptr=ptr.next
before.next=last
ptr=before
while ptr!=None:
print('\t[%2d]\t[%-7s]\t[%3d]' % (ptr.no, ptr.name, ptr.salry))
ptr = ptr.next
参考图解数据结构书