Beispiel #1
0
class Queue:
    def __init__(self, type="array"):
        if type == "array":
            self.__array = ArrayDeque()
        else:
            self.__array = LinkedList()

    def add(self, value):
        self.__array.push_back(value)

    def remove(self):
        return self.__array.pop_front()

    def get_size(self):
        return self.__array.get_size()
Beispiel #2
0
class Stack:
    def __init__(self, type="array"):
        if type == "array":
            self.__array = ArrayDeque()
        else:
            self.__array = LinkedList()

    def push(self, value):
        self.__array.push_front(value)

    def pop(self):
        return self.__array.pop_front()

    def get_size(self):
        return self.__array.get_size()
Beispiel #3
0
class Stack:
    def __init__(self, datastructure = "array"):
        if datastructure == "array":
            self.datastructure = ArrayDeque()
        else:
            self.datastructure = LinkedList()

    def push(self, value):
        self.datastructure.push_front(value)

    def pop(self):
        return self.datastructure.pop_front()

    def get_size(self):
        return self.datastructure.get_size()
Beispiel #4
0
class Queue:
    def __init__(self, datastructure="array"):
        if datastructure == "array":
            self.datastructure = ArrayDeque()
        else:
            self.datastructure = LinkedList()

    def add(self, value):
        self.datastructure.push_back(value)

    def remove(self):
        return self.datastructure.pop_front()

    def get_size(self):
        return self.datastructure.get_size()
Beispiel #5
0
class Queue:
    def __init__(self, type: str):
        if type == 'array':
            self.container = ArrayDeque()
        else:
            self.container = LinkedList()

    def add(self, element):
        self.container.push_back(element)

    def remove(self):
        return self.container.pop_front()

    def get_size(self):
        return self.container.get_size()
Beispiel #6
0
class Stack:
    def __init__(self, type: str):
        if type == 'array':
            self.container = ArrayDeque()
        else:
            self.container = LinkedList()

    def push(self, element):
        self.container.push_front(element)

    def pop(self):
        return self.container.pop_front()

    def get_size(self):
        return self.container.get_size()
Beispiel #7
0
class Queue:
    def __init__(self, _type_):
        self.type = _type_
        if self.type == 'array':
            self.queue = ArrayDeque()
        elif self.type == 'linked':
            self.queue = LinkedList()

    def add(self, value):
        self.queue.push_back(value)

    def remove(self):
        return self.queue.pop_front()

    def get_size(self):
        return self.queue.get_size()
Beispiel #8
0
class Queue:
    def __init__(self, a_type):

        if a_type == 'array':
            self.instance = ArrayDeque()
        else:
            self.instance = LinkedList()

    def add(self, value):
        return self.instance.push_back(value)

    def remove(self):
        return self.instance.pop_front()

    def get_size(self):
        return self.instance.get_size()
Beispiel #9
0
class Stack():
    def __init__(self, a_type):

        if a_type == 'array':
            self.instance = ArrayDeque()
        else:
            self.instance = LinkedList()

    def push(self, value):
        return self.instance.push_front(value)

    def pop(self):
        return self.instance.pop_front()

    def get_size(self):
        return self.instance.get_size()
Beispiel #10
0
class Stack:
    def __init__(self, type: str):
        if type == "array":
            self.PEZ = ArrayDeque()
        elif type == "linked":
            self.PEZ = LinkedList()

    def push(self, val):
        self.PEZ.push_front(val)

    def pop(self):
        if self.PEZ.is_empty():
            return None
        else:
            return self.PEZ.pop_front()

    def get_size(self):
        return self.PEZ.get_size()
Beispiel #11
0
class Queue:
    def __init__(self, type: str):
        if type == "array":
            self.my_queue = ArrayDeque()
        elif type == "linked":
            self.my_queue = LinkedList()

    def add(self, val):
        self.my_queue.push_back(val)

    def remove(self):
        if self.my_queue.is_empty():
            return None
        else:
            return self.the_queue.pop_front()
    
    def get_size(self):
        return self.my_queue.get_size()
class Queue:
    def __init__(self):
        # Pick one of these to use.
        # Stack must have the container you dont choose for Queue

        self.container = LinkedList()
        #self.container = ArrayDeque()

    def add(self, data):
        self.container.push_back(data)

    def remove(self):
        return self.container.pop_front()

    def get_size(self):
        return self.container.get_size()

    def __str__(self):
        return str(self.container)
Beispiel #13
0
    def __init__(self):
        pass
        # Pick one of these to use.
        # Stack must have the container you dont choose for Queue

        self.container = LinkedList()
Beispiel #14
0
 def __init__(self, the_type):
     if the_type == "array":
         ArrayDeque.__init__(self)
     elif the_type == "linked":
         LinkedList.__init__(self)
Beispiel #15
0
 def __init__(self, type: str):
     if type == "array":
         self.my_queue = ArrayDeque()
     elif type == "linked":
         self.my_queue = LinkedList()
Beispiel #16
0
 def __init__(self, datastructure="array"):
     if datastructure == "array":
         self.datastructure = ArrayDeque()
     else:
         self.datastructure = LinkedList()
Beispiel #17
0
 def __init__(self, type="array"):
     if type == "array":
         self.__array = ArrayDeque()
     else:
         self.__array = LinkedList()
Beispiel #18
0
    def __init__(self, a_type):

        if a_type == 'array':
            self.instance = ArrayDeque()
        else:
            self.instance = LinkedList()
 def get_type(self, type_input_str):
     '''Returns the type of given string input'''
     if type_input_str == 'array':
         return ArrayDeque()
     elif type_input_str == 'linked':
         return LinkedList()
Beispiel #20
0
 def __init__(self, _type_):
     self.type = _type_
     if self.type == 'array':
         self.queue = ArrayDeque()
     elif self.type == 'linked':
         self.queue = LinkedList()
Beispiel #21
0
from my_linked_list import LinkedList, Node, BetterLinkedList
from my_circular_linked_list import CircularLinkedList

llist = LinkedList()
head = Node('0')
llist.head = head

new_node = Node('1')
head.next = new_node

new_node_1 = Node('2')
new_node.next = new_node_1

llist._print_()

bllist = BetterLinkedList(['0', '1', '2', '4', '5'])

print('Adding -1 to head')
bllist.add_first(Node('-1'))
print('Adding -2 to head')
bllist.add_first(Node('-2'))

print('Adding 6 to end')
bllist.add_last(Node('6'))
print('Adding 7 to end')
bllist.add_last(Node('7'))

print('Adding 3 after 2')
bllist.add_after('2', '3')

#Uses __iter__ function
Beispiel #22
0
print(deque)
print(deque.pop_front())
print(deque.pop_front())
print(deque.pop_front())
print("container of size: " + str(deque.get_size()) + ":")
print(deque)
print(deque.pop_front())
print(deque.pop_back())
print(deque.pop_front())
print(deque.pop_back())
print("container of size: " + str(deque.get_size()) + ":")
print(deque)

print("\nTESTING LINKED_LIST\n")

lis = LinkedList()
lis.push_back(3)
lis.push_back(1)
lis.push_back(6)
lis.push_back(9)
print("container of size: " + str(lis.get_size()) + ":")
print(lis)
print(lis.pop_front())
print(lis.pop_front())
print("container of size: " + str(lis.get_size()) + ":")
print(lis)
lis.push_front(11)
lis.push_front(16)
lis.push_front(13)
print("container of size: " + str(lis.get_size()) + ":")
print(lis)
Beispiel #23
0
 def __init__(self, type: str):
     if type == 'array':
         self.container = ArrayDeque()
     else:
         self.container = LinkedList()