Guest User

Untitled

a guest
Jun 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. from ctypes import *
  2.  
  3.  
  4. class Node(Structure):
  5. pass
  6.  
  7. Node._fields_ = [("next", POINTER(Node)),
  8. ("foo", c_int)]
  9.  
  10.  
  11. class List(Structure):
  12. _fields_ = [("head", POINTER(Node))]
  13.  
  14. def __init__(self, foo):
  15. self.head = pointer(Node(None, c_int(foo)))
  16.  
  17. def append(self, extra_foo):
  18. p = self.head
  19. while p.contents.next:
  20. p = p.contents.next
  21. p.contents.next = pointer(extra_foo)
  22.  
  23. def __str__(self):
  24. value = ''
  25. p = self.head
  26. while p:
  27. value += str(p.contents.foo)
  28. p = p.contents.next
  29. return value
  30.  
  31.  
  32. def main():
  33. l = List(0)
  34. for x in range(1, 10):
  35. l.append(Node(None, c_int(x)))
  36.  
  37. print l
  38.  
  39.  
  40. if __name__ == '__main__':
  41. main()
Add Comment
Please, Sign In to add comment