
# Descending priority, the higher the key, the higher the priority
class PriorityQueueArrayUnordered:
	
    # Constructor, Time O(1), Space O(1)
    def __init__(self, capacity) :
        self.maxSize = capacity
        self.pqArray = {}
        self.length = 0
    
    # Add at the end without sorting, Time O(1), Space O(1)
    def enqueue(self, value) :
        if (self.length == self.maxSize) :
            print("priority queue is full, cannot enqueue " + str(value))
            return      
        self.pqArray[self.length] = value
        self.length += 1

    # Find the biggest and delete it, Time O(n), Space O(1)
    def dequeue(self) : 
        if (self.isEmpty()) :
            print("queue is empty")
            return None
        maxIndex = 0
        for  i in range(1, self.length):  #search for biggest
            if (self.pqArray[i] > self.pqArray[maxIndex]) : 
                maxIndex = i; 
        item = self.pqArray[maxIndex]; 
        self.length -= 1 
        self.pqArray[maxIndex] = self.pqArray[self.length]; #move the last to this spot
        return item
    
    #Find the biggest and return it, Time O(n), Space O(1)
    def peek(self) : 
        if (self.isEmpty()) :
            print("queue is empty")
            return None
        maxIndex = 0
        for  i in range(1, self.length):  #search for biggest
            if (self.pqArray[i] > self.pqArray[maxIndex]) : 
                maxIndex = i; 
        return self.pqArray[maxIndex]
    
    # print all, in insert order, Time O(n), Space O(1)
    def print(self) :
        line = "Priority Queue: "
        for i in range (0, self.length):
             line += str(self.pqArray[i]) + " "
        print(line)
     
    # Return the length, Time O(1), Space O(1)
    def size(self) :
        return self.length
   
    # Check empty, Time O(1), Space O(1)
    def isEmpty(self) : 
        return self.length == 0 

pq = PriorityQueueArrayUnordered(5)
pq.enqueue(20)
pq.enqueue(12)
pq.enqueue(30)
pq.enqueue(15)     
pq.enqueue(54)
pq.enqueue(66)
pq.print()
print("size: " + str(pq.size()))
print("peek: " + str(pq.peek()))

#dequeue
pq.dequeue()
pq.print()
print("size: " + str(pq.size()))
print("peek: " + str(pq.peek()))

#enqueue again
pq.enqueue(66)
pq.enqueue(98)
pq.print()
print("size: " + str(pq.size()))
print("peek: " + str(pq.peek()))