import random class node: def __init__(self,val): self.val=val self.next=None class mylist: def __init__(self): self.head=None self.tail=None self.rhead=None def push(self,val): if self.head is None: self.head=node(val) self.tail=self.head else: self.tail.next=node(val) self.tail=self.tail.next def myprint(self): temp=self.head a=[] while temp is not None: a.append(temp.val) temp=temp.next print a def myrevprint(self): temp=self.rhead a=[] while temp is not None: a.append(temp.val) temp=temp.next print a def myrev(self): if self.head is None: self.rhead=None else: temp=self.head while temp is not None: if self.rhead is None: self.rhead=temp temp=temp.next self.rhead.next=None else: tmp=self.rhead self.rhead=temp temp=temp.next self.rhead.next=tmp a=mylist() for i in range(1,25): a.push(int(random.random()*(1<<10))) a.myprint() a.myrev() a.myrevprint()
Standard input is empty
[130, 443, 323, 366, 176, 158, 178, 778, 107, 450, 75, 984, 561, 791, 808, 850, 398, 284, 585, 703, 806, 530, 430, 788] [788, 430, 530, 806, 703, 585, 284, 398, 850, 808, 791, 561, 984, 75, 450, 107, 778, 178, 158, 176, 366, 323, 443, 130]