예제 #1
0
class Queue:
    __slots__ = "ring_buffer"

    def __init__(self, capacity):
        if capacity < 0:
            print("Cannot have a negative list")
            exit()
        elif isinstance(capacity, int):
            self.ring_buffer = RingBuffer(capacity)
        else:
            print("Incorrect format of Capacity")

    def __str__(self):
        return self.ring_buffer.__str__()

    def enqueue(self, data):
        if (data == None):
            print("Data has to be sent!!")
            return -1
        else:
            self.ring_buffer.insert_keep_old(data)

    def dequeue(self):
        self.ring_buffer.remove_oldest()

    def peek(self):
        return self.ring_buffer.head

    def capacity(self):
        return self.ring_buffer.capacity()
예제 #2
0
class Queue:
    __slots__ = "ring_buffer", "link"

    def __init__(self, capacity):
        self.ring_buffer = RingBuffer(capacity)

    def __str__(self):
        return self.ring_buffer.__str__()

    def enqueue(self, value):
        self.ring_buffer.insert_keep_old(value)

    def dequeue(self):
        self.ring_buffer.remove_oldest()

    def peek(self):
        return self.ring_buffer.head

    def capacity(self):
        return self.ring_buffer.capacity()
예제 #3
0
파일: stack.py 프로젝트: neelkirit/CSCI-603
class Stack:
    __slots__ = "ring_buffer"

    def __init__(self, capacity):
        self.ring_buffer = RingBuffer(capacity)

    def __str__(self):
        return self.ring_buffer.__str__()

    def push(self, value):
        self.ring_buffer.insert_keep_new(value)

    def pop(self):
        self.ring_buffer.remove_newest()

    def capacity(self):
        self.ring_buffer.capacity()

    def peek(self):
        return self.ring_buffer.head
예제 #4
0
list1.insert_keep_new("1")

print("-----------------------")
print("Test Case of Stack")
print(
    "Assumed Stack capacity is 5 for testing. All the test cases below are according to size 5"
)
sizeOfS = int(input("Enter size of Stack"))
list1 = Stack(sizeOfS)
print("Adding 1")
list1.push(1)
print("Adding 2")
list1.push(2)
print("Adding 3")
list1.push(3)
list1.__str__()
print("poping ", list1.peek())
list1.pop()
list1.__str__()
print("Pushing 4")
list1.push(4)
print("Pushing 5")
list1.push(5)
list1.__str__()
print("Pushing 6")
list1.push(6)
list1.__str__()
print("Pushing 7")
list1.push(7)
list1.__str__()
print("Pushing 8")