title: Priority queue using heap (Whats wrong with my code?)
body: <p>I am doing an assignment priority queue using heap
  these are instructions for every commands</p>
  
  <ol>
  <li>Add element create an element with the id an priority given
  add the element to the queue
  produce no output for this command</li>
  <li>Delete element deleted the element with specified id from the queue
  produce no output for this command</li>
  <li>Reset priority locate the element with the specified id within the priority queue change the element’s priority to the value requested produce no output for this command</li>
  <li>read query the highest priority element from the queue
  print the current (overall total) command number, the element id and priority on
  standard output, followed by a newline, as follows:
  i.e.: at command number 5087, top of queue is element 99 with priority 1
  do not print the "read command number" at this time</li>
  <li>Pop query the highest priority element and remove it from the queue
  produce no output for this command</li>
  <li>finalize successively read and pop all elements remaining in the queue
  provide output consistent with the read command for each remaining element</li>
  </ol>
  
  <hr>
  
  <pre><code>void pop(int heapSize){
    heap[0]=heap[heapSize-1]; //overwrite
    heapSize--;
    heapifyDown(0);
  }
  
  void heapifyDown(int insert){
    int nextStep = insert;
    right = (insert + 1)*2;
    left=right-1;
    if (left&lt;heapSize){
      nextStep=left;
    }
    if((right&lt;heapSize)&amp;&amp;(heap[right].priority&lt;heap[left].priority)){
      nextStep=right;
    }
    while(heap[nextStep].priority &lt; heap[insert].priority){
      swap(heap[nextStep, heap[insert]]);
      insert=nextStep;
    }
    right=()insert+1)*2;
    leaft=right-1;
    if(left&lt;heapSize){
      nextStep=left;
    }
    if((right&lt;heapSize)&amp;&amp;heap[right].priority&lt;heap[left].priority){
      nextStep=right;
    }
  }
  
  void deleteElement(heapElement, int element, int heapSize){ 
  
    int index; // to remember the deleted node's position
    for(int i=1; i &lt;heapSize; i++){
  
      if (heap[i] == element){
          heap[i]=NULL;        
          index = i; // position of removed element;
          break;
      }
    }
  
    // move the last element(A[num_items_in_array]) in array to the
    // position of removed element; heapify up/down according to
    // priority
  }
  
  void reset(int element, int newP){
    for(int i=1; i &lt;heapSize; i++){
      if (heap[i] == element){
          heap[i].priority = newP;
          heapifyDown(heap[i], newP);
          heapifyUp(heap[i], newP);
      }
    }
  }
  
  void read(){
    if(!heap[].empty()){
      cout &lt;&lt; heap[0];
    }
  }
  
  void finalize(){
    for(i=1; i&lt;heapSize; i++){
      cout &lt;&lt; heap[i];
      heap[i]=NULL;
    }   
  }
  
  int main()
  {
    int case, counter;
    elment_priority node;
    while(counter &lt; 1000){
      cin &gt;&gt; case;
      cin &gt;&gt; node.element;
      cin &gt;&gt; node.priority;
  
      int addSum, deleteSum, resetSum, readSum, popSum,
          finalizeSum, totalSum=0;
      switch(case) {
          case 1:
              addElement(heapElement,node.element, heapSize);
              addSum++;
          case 2:
              deleteElement(heapElement,node.element, heapSize);
              deleteSum++:
          case 3:
              reset(node.element, node.priority);
              resetSum++;
          case 4:
              read();
              readSum++;
          case 5:
              pop();
              popSum++;
          case 6:
              finalize();
              finalizeSum++;
          default: 
              cout&lt;&lt;"Cannot Process Command :"
                  + case + node.element
                  + node.priority + ": wrong command";
      }
    }
  
    cout &lt;&lt; "\n";
    cout &lt;&lt; "\n";
    cout &lt;&lt; "================================================================";
    cout &lt;&lt; addSum &lt;&lt; "total add commands processed.\n";
    cout &lt;&lt; deleteSum &lt;&lt; "total delete commands processed.\n";
    cout &lt;&lt; resetSum &lt;&lt; "total reset commands processed.\n";
    cout &lt;&lt; readSum &lt;&lt; "total read commands processed.\n";
    cout &lt;&lt; popSum &lt;&lt; "total pop commands processed.\n";
    cout &lt;&lt; finalizeSum &lt;&lt; "total finalize commands processed.\n";
    cout &lt;&lt; totalSum &lt;&lt; "total commands processed.\n";
  
  }
  </code></pre>