def top(self):  #returns the top element
     #complexity O(1)
     x = Option()
     if self.__elements.emptyList():
         x.setOp(False)
     else:
         x.setEl(self.__elements.getEl(0))
     return x  #returns empty option if list is empty
Exemple #2
0
 def delete(self, el):
     #complexity O(1)
     x = Option()
     if self.contains(el):
         x.setEl(el)
         self.__vector[el] = False
         return x
     print("Element is not in the set", el)
     return x
Exemple #3
0
 def pop(self): #pops the first elment if possile
     #complexity O(1)
     x = Option()
     if self.__elements.emptyList():
         raise Exception("Stack is Empty") #raises exception if list is empty
     else:
         x.setEl(self.__elements.getEl(0));
         self.__elements.deletFirst() #deletes the First element if possible
     return x 
Exemple #4
0
 def delete(self, n):
     #complexity O(n)
     x = Option()
     while self.__iter.hasNext():
         if n is self.__iter.iter.getHead():
             self.__iter.iter.deletFirst(
             )  #delets the element from the list
             self.__iter.init()
             x.setEl(n)
             return x
         self.__iter.Next()
     print("Element is not in the set", n)
     return x
 def dequeue(self):  #deletes the last elemet in the fill
     #complexity O(n) if empty is empty else complexity O(1)
     if self.__empty.emptyList():
         if self.__fill.emptyList():
             raise Exception("Queue is Empty")
         self.__empty = self.__fill.reverse(Nil())  #takes linear time
         self.__fill = Nil()
     op = Option()
     if self.isEmpty():
         op.setOp(False)
     else:
         op.setEl(self.__empty.getEl(0))
         self.__empty.deletFirst()
     return op  #returns the value