33.python 链表反转

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

参考图解数据结构书

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值