Click here to Skip to main content
15,889,721 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
    private void DequeueActionPerformed(java.awt.event.ActionEvent evt) {                                        
        a.dequeue();
      
        if(a.count<=0){
         JOptionPane.showMessageDialog(this, "This is underflow", "Message", EXIT_ON_CLOSE);
        } else{
         JOptionPane.showMessageDialog(this, "Dequeued: "+a.Queue[a.count].toString(), "Message", EXIT_ON_CLOSE);
        }
        refresh();
}


private void EnqueueActionPerformed(java.awt.event.ActionEvent evt) {                                        

        a.enqueue(jTextFieldElement.getText());
        jTextFieldElement.setText("");
        if(a.count==a.size ||a.count < (size-1)){
         JOptionPane.showMessageDialog(this, "This is overflow", "Message", EXIT_ON_CLOSE);
        }
        refresh();
       
        
    }       


 public boolean enqueue(Object element)
{
    if( count==size  )
    return false;

    Queue[count] = element;
    count++;

    return true;

}

public Object dequeue()
{
    if(count==0 )
    return false;

    count--;
    return Queue[count];
}


What I have tried:

I have problem with these codes. When i enter size=2,size will be 2. And when i enter 1 number,it is working correctly,but when i enter 2nd number ,it is working wrongly,it add this number ,but it must not add it and it must show "overflow " message.becuase for queues the last place must be empty,it must not add number to the last place of array.how can i solve this?what is wrong with my code?


and the 2nd problem.

the second problem is related with "underflow".
when i enter 2 for size,then i enter 2number.and then when i dequeue these numbers,after 1st number it shows "underflow" message.but it must show this message when array is empty and i want to dequeue it.

Sorry for my english.
and please help for solving these problems.

Thanks in advance.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900