SHARE
TWEET

SList

a guest Nov 14th, 2017 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class MyNode:
  2.     def __init__(self, value):
  3.         self.nextLink = None
  4.         self.value = value
  5.  
  6.  
  7. class MyList:
  8.  
  9.     def __init__(self):
  10.         self.head = None
  11.         self.length = 0
  12.  
  13.     def insert(self, value):
  14.         newNode = MyNode(value)
  15.         newNode.nextLink = self.head
  16.         self.head = newNode
  17.         self.length+=1
  18.  
  19.     def size(self):
  20.         return self.length
  21.  
  22.     def pop(self, value):
  23.         temp = self.head
  24.         i=self.length
  25.         while(i > value):
  26.             i-=1
  27.             temp = temp.nextLink
  28.         return temp.value
  29.         self.length-=1
  30.  
  31. list = MyList()
  32.  
  33. list.insert(5)
  34. list.insert(7)
  35. list.insert(1)
  36.  
  37. print(list.pop(1))
RAW Paste Data
Top