fork download
  1. import random
  2. class node:
  3. def __init__(self,val):
  4. self.val=val
  5. self.next=None
  6. class mylist:
  7. def __init__(self):
  8. self.head=None
  9. self.tail=None
  10. self.rhead=None
  11. def push(self,val):
  12. if self.head is None:
  13. self.head=node(val)
  14. self.tail=self.head
  15. else:
  16. self.tail.next=node(val)
  17. self.tail=self.tail.next
  18. def myprint(self):
  19. temp=self.head
  20. a=[]
  21. while temp is not None:
  22. a.append(temp.val)
  23. temp=temp.next
  24. print a
  25. def myrevprint(self):
  26. temp=self.rhead
  27. a=[]
  28. while temp is not None:
  29. a.append(temp.val)
  30. temp=temp.next
  31. print a
  32. def myrev(self):
  33. if self.head is None:
  34. self.rhead=None
  35. else:
  36. temp=self.head
  37. while temp is not None:
  38. if self.rhead is None:
  39. self.rhead=temp
  40. temp=temp.next
  41. self.rhead.next=None
  42. else:
  43. tmp=self.rhead
  44. self.rhead=temp
  45. temp=temp.next
  46. self.rhead.next=tmp
  47.  
  48. a=mylist()
  49. for i in range(1,25):
  50. a.push(int(random.random()*(1<<10)))
  51. a.myprint()
  52. a.myrev()
  53. a.myrevprint()
Success #stdin #stdout 0.02s 10328KB
stdin
Standard input is empty
stdout
[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]