this is my first question here ever, so formatting and such might be a little off. Please don't hate me :)
So what I am doing is making a class called PQUEUE and what I have already is:
class qNode:
def __init__(self,data=None, next=None):
self.data = data
self.next = next
def __str__(self):
return str(self.data)
class PQUEUE:
def __init__(self):
self.head = None
self.foot = None
def push(self, value=None, priority=0):
#This is what I want to make
def pop(self):
x = self.front.data
self.front = self.front.next
return x
def clear(self):
self._head = None
self._foot = None
I am trying to make make a Priority Queue class (as you can see) without using heapq/queue classes or the built-in list methods.
What I can't figure out is how I would go on about doing this. I've tried searching everywhere online but everywhere I look people are doing this by either importing or using the built-in list methods.
Help very appreciated ! :)
bisect.bisect_left()to compute the insert index, and then uselist.insert().bisectseems to be about as contrary to the spirit of the task as usingheapq. Also, a sorted list has linear-time insertion instead of the logarithmic-time insertion of a binary heap.