Esempio n. 1
0
 def generate(self, linked_list, pos, amount):
     rez = Iterator(int(amount))
     to_return = LinkedList()
     for num in rez:
         to_return.add_tail(num)
     # print("\n to_return strategy 1",) # тут правильний ліст
     # to_return.print()
     print()
     return super().generate(linked_list, pos, to_return)
Esempio n. 2
0
    def __init__(self):
        '''
        Initializes an empty stack with no nodes.

        Inherited Attributes:
            - head
            - _length
        '''
        LinkedList.__init__(self)
Esempio n. 3
0
    def __init__(self):
        '''
        Initializes an empty deque with no items

        Inherited Attributes:
            - head
            - _length
        '''

        LinkedList.__init__(self)
Esempio n. 4
0
    def add_rear(self, item):
        '''
        item -> any type: data to add to the end of the deque

        Adds an item to the end of the deque. This functionality
        is the same as the append() method defined in the LinkedList class.

        Examples:
            - add_rear(5): 2 -> 3.5 ===> 2 -> 3.5 -> 5
            - add_rear(12): Empty Deque ===> 12
        '''

        LinkedList.append(self, item)
Esempio n. 5
0
    def add_front(self, item):
        '''
        item -> any type: data to add to the front of the deque

        Adds an item to the front of the deque. This functionality
        is the same as the add() method defined in the LinkedList class.

        Examples:
            - add_front(-6.7): 1 -> True ===> -6.7 -> 1 -> True
            - add_front(5): Empty Deque ===> 5
        '''

        LinkedList.add(self, item)
Esempio n. 6
0
 def generate(self, linked_list, pos, file_name):
     f = open(file_name)
     to_ints = f.read()
     to_ints = to_ints.split(", ")
     res = LinkedList()
     for i in range(len(to_ints)):
         if represents_int(to_ints[i]):
             to_ints[i] = int(to_ints[i])
             res.add_tail(to_ints[i])
         else:
             print("Element ", to_ints[i],
                   "in file is not int. Its position is ", i + 1)
     return super().generate(linked_list, pos, res)
Esempio n. 7
0
    def push(self, item):
        '''
        item -> any type: data to add to the front of the stack
        return -> nothing

        Adds an item to the front of the stack. This functionality is
        the same as the add() method defined in the LinkedList class.

        Examples:
            - push(5): 2 -> 3 -> True ===> 5 -> 2 -> 3 -> True
            - push(-5.6): Empty Stack ===> -5.6
            - push(2.3): 4 ===> 2.3 -> 4
        '''

        LinkedList.add(self, item)
Esempio n. 8
0
    def enqueue(self, item):
        '''
        item -> any type: data to add to the end of the queue
        return -> nothing

        Adds an item to the end of the queue. This functionality is
        the same as the append() method defined in the LinkedList class.

        Examples:
            - enqueue(5): 2 -> 3 ===> 2 -> 3 -> 5
            - enqueue(True): Empty Queue ===> True
            - enqueue(23.5): 2 ===> 2 -> 23.5
        '''

        LinkedList.append(self, item)
Esempio n. 9
0
    def pop(self):
        '''
        return -> any type: first item in stack

        Removes the first item in the stack and returns it. The
        functionality is similar to the pop() method defined in the
        LinkedList class except an argument of zero is necessary.

        Examples:
            - pop(): 2 ===> 2 (returned value), Empty Stack (modified stack)
            - pop(): 5 -> True -> 6 ===> 5 (returned value), True -> 6 (modified stack)
        '''

        return LinkedList.pop(self, 0)
Esempio n. 10
0
    def dequeue(self):
        '''
        return -> any type: first item in queue

        Removes and returns the first item in the queue. This
        functionality is similar to the pop() method defined
        in the LinkedList class except an argument of zero is
        necessary.

        Examples:
            - dequeue(): 6 -> 3 -> 5 ===> 3 -> 5
            - dequeue(): True -> 25 ===> 25
        '''

        return LinkedList.pop(self, 0)
Esempio n. 11
0
    def remove_rear(self):
        '''
        return -> any type: last item in deque

        Removes the last item in the deque and returns it. The
        functionality is the same as the pop() method defind in
        the LinkedList class.

        Examples:
            - remove_rear(): 2 -> True -> False ===> False (returned value)
                             2 -> True (modifed Deque)
            - remove_rear(): True -> 3.4 ===> 3.4 (returned value)
                             3.4 (modified Deque)
        '''

        return LinkedList.pop(self)
Esempio n. 12
0
    def remove_front(self):
        '''
        return -> any type: first item in deque

        Removes the first item in the Deque and returns it. The
        functionality is similar to the pop() method defined in
        the LinkedList class except an argument of 0 is required.

        Examples:
            - remove_front(): 5 -> 2 -> 3 ===> 5 (returned value)
                              2 -> 3 (modified Deque)
            - remove_front(): 2 ===> 2 (returned value)
                              Empty Deque (modified Deque)
        '''

        return LinkedList.pop(self, 0)