Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from ctypes import *
- class Node(Structure):
- pass
- Node._fields_ = [("next", POINTER(Node)),
- ("foo", c_int)]
- class List(Structure):
- _fields_ = [("head", POINTER(Node))]
- def __init__(self, foo):
- self.head = pointer(Node(None, c_int(foo)))
- def append(self, extra_foo):
- p = self.head
- while p.contents.next:
- p = p.contents.next
- p.contents.next = pointer(extra_foo)
- def __str__(self):
- value = ''
- p = self.head
- while p:
- value += str(p.contents.foo)
- p = p.contents.next
- return value
- def main():
- l = List(0)
- for x in range(1, 10):
- l.append(Node(None, c_int(x)))
- print l
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment