c++ - Dequeue in a priority queue -
i have implemented priority queue array (school work), , looks below:
int dequeue(int a[], int n){ int i, numbertodequeue; numbertodequeue = a[0]; for(i = 0; < n; i++){ a[i] = a[i+1]; } return numbertodequeue; }
dequeue in priority queue should take o(1) time.
however, in code, takes o(1) time dequeue ,
o(n) time shift elements front 1 index.
i wondering if there's better solution has time complexity of o(1).
all form of reply appreciated.
int dequeue(int a[], int n){ //provided numbers in ascending order int numbertodequeue; numbertodequeue = a[n - 1]; n--; return numbertodequeue; }
Comments
Post a Comment