Here is my implementation for a queue using doubly linked list:
QUEUE-EMPTY
if L.head == NIL
return True
else return False
QUEUE(x):
if L.head == NIL:
x.prev = NIL
L.head = x
else
cur = L.head
while cur.next != NIL
cur = cur.next
cur.next = x
x.prev = cur
x.next = NIL
DEQUEUE():
x = L.head
L.head = x.next
x.next.prev = L.head
return x
How to improve ? Is that correct ?
Is there a mean to make QUEUE O(1) ?
thanks !!