Exemple #1
0
 def push_at(self, data, stack_no):
     if self.stacks[stack_no] is None:
         self.stacks[stack_no] = Node(data)
     else:
         new_head = Node(data)
         new_head.next_node = self.stacks[stack_no]
         self.stacks[stack_no] = new_head
Exemple #2
0
 def push(self, data):
     if self.head is None:
         self.head = Node(data)
     else:
         new_head = Node(data)
         new_head.next_node = self.head
         self.head = new_head
 def push(self, data):
     if self.head is None:
         self.head = Node(data)
     else:
         head = self.head
         while self.head.next_node is not None:
             self.head = self.head.next_node
         self.head.next_node = Node(data)
         self.head = head
 def push(self, data):
     if not self.stacks:
         self.stacks = [Node(data, position=self.__stack_capacity)]
     else:
         head = self.stacks[0]
         if head.position > 1:
             new_head = Node(data, position=head.position - 1)
             new_head.next_node = head
             self.stacks[0] = new_head
         else:
             new_head = Node(data, position=self.__stack_capacity)
             self.stacks.insert(0, new_head)
 def __init__(self, data=None):
     if data is not None:
         self.stacks = [Node(data, position=self.__stack_capacity)]
Exemple #6
0
 def __init__(self, data=None, stack_no=None):
     if (data is not None) & (stack_no is not None):
         self.stacks = [None, None, None]
         self.stacks[stack_no] = Node(data)
Exemple #7
0
 def __init__(self, data=None):
     self.head = None
     if data is not None:
         self.head = Node(data)