C# 优先级队列删除优先级相同的项目第一个输入的项目

C# 优先级队列删除优先级相同的项目第一个输入的项目,c#,queue,priority-queue,C#,Queue,Priority Queue,我已经创建了一个优先级队列,它按顺序输入项目并按顺序删除它们。即使两个数字具有相同的优先级,它也会删除第一个输入的数字 如果有三个号码具有相同的优先级,则不会删除第一个号码。我该怎么做,还是应该这样做 出列功能: 复接功能: public-void-ReheapDown(int-root,int-bottom) { int maxchild、rightchild、leftchild; leftchild=根*2+1; rightchild=根*2+2; 如果(leftchild在这一行中 if

我已经创建了一个优先级队列,它按顺序输入项目并按顺序删除它们。即使两个数字具有相同的优先级,它也会删除第一个输入的数字

如果有三个号码具有相同的优先级,则不会删除第一个号码。我该怎么做,还是应该这样做

出列功能: 复接功能:
public-void-ReheapDown(int-root,int-bottom)
{
int maxchild、rightchild、leftchild;
leftchild=根*2+1;
rightchild=根*2+2;
如果(leftchild在这一行中

if (elements[leftchild].priority <= elements[rightchild].priority)
现在,您将删除
1
。然后将
1
替换为
3

      3
    /   \
   2     2*
在您的
ReheapDown
方法中,父对象有两个子对象,您选择的是最小的子对象。当您比较这两个
2
时,您有以下代码:

if (elements[leftchild].priority <= elements[rightchild].priority)
    maxchild = rightchild;
else
    maxchild = leftchild;
接下来要删除的内容是
2*

那么,您可能会想,如果您更改

      1
    /   \
   2     2*
  /
 3
      3
    /   \
   2     2*
if (elements[leftchild].priority <= elements[rightchild].priority)
    maxchild = rightchild;
else
    maxchild = leftchild;
      2*
    /   \
   2     3
      1
    /   \
   2*    2
  /
 3
      3
    /   \
   2*    2