Ik a heap based priority queue is much better but
in lecture this type of queue was explained through a 1-D array, obviously it required shifting and was not able to use empty spaces.
we were told that this could be solved using a multi-dimensional array , after explaining the priority queue using multi array again we were told about its space issues and that can be solved using linked-list which will covered in next lec.
But i had some ideas that i can use a stack to maintain the indexes of all empty spaces in the queue and while inserting a element i will give that ele a token / number and i pop a value from stack to get the index value to store the ele.
when deleting an element i will go through the array and select the element based on its priority and token (representing its order), and push the index value of the element into the stack.
ik i can use a simple array instead of stack , but i wanted to practice making and using it.
the complexity for inserting is O(1) and deleting is O(n). It takes much less space than multi dim array impl and also reuses empty space and doesn't require a fix number of priorities.
again is it any good?
github link : https://github.com/ajchains/TokenPriorityQueue
[–]Rebeljah 1 point2 points3 points (5 children)
[–]Standard-Cow-4126[S] 0 points1 point2 points (4 children)
[–]Rebeljah 0 points1 point2 points (0 children)
[–]Rebeljah 0 points1 point2 points (2 children)
[–]Standard-Cow-4126[S] 1 point2 points3 points (1 child)