在优先级队列中取消排队
Dequeue in a priority queue
我已经用数组(学校作业)实现了优先级队列,如下所示:
int dequeue(int a[], int n){
int i, numberToDequeue;
numberToDequeue = a[0];
for(i = 0; i < n; i++){
a[i] = a[i+1];
}
return numberToDequeue;
}
在优先级队列中取消排队应该需要 O(1) 时间。
但是,在我的代码中,取消排队需要 O(1) 时间,并且
O(n) 将所有元素移到前面 1 个索引的时间。
我想知道是否有更好的解决方案具有 O(1) 的时间复杂度。
所有形式的答复将不胜感激。
int dequeue(int a[], int n){ //provided that the numbers are in ascending order
int numberToDequeue;
numberToDequeue = a[n - 1];
n--;
return numberToDequeue;
}
相关文章:
- 挂起和取消挂起一个文件DLL
- 如何取消对nullptr的屏蔽,返回正确的对象
- C++取消引用指针.为什么会发生变化
- 使用取消引用的指针的多态性会产生意外的结果.为什么?
- 取消引用运算符不能重载
- 使用指针在C++中排队/取消排队?
- 取消排队不适用于从双链表继承的队列类
- c++ 无效指针从空闲列表中取消排队
- 如何使用 QPoint 指针成员对类进行排队和取消排队
- 队列类的取消排队方法"Aborted (core dumped)"错误
- 模板取消排队方法具有未声明的标识符
- 如果最初发出 IO 的线程在窗口 8 下的 ReadFile 中阻塞,则 GetQueuedCompletionStatus 无法将 IO 从 IOCP 中取消排队
- 循环取消排队实现错误
- 如果队列为空,取消排队应返回什么
- 具有 O(1) 取消排队和 O(无论什么)排队的优先级队列
- 在优先级队列中取消排队
- 当取消请求排队时,pthread_cancel()将如何响应
- 取消排队迭代器不可取消引用
- OpenAL取消排队错误代码,不完整的文档
- 以原子方式取消排队的最简单方法