Está en la página 1de 2

SUMAR LOS ELEMENTOS DE LA COLA

private void
SumarLosElementosDeLaColaActionPerformed(java.awt.event.ActionEvent evt) {
//SUMAR LOS ELEMENTOS DE LA COLA
int elem,suma =0;

Queue aux =new LinkedList();

while(!q.isEmpty()){

elem=Integer.parseInt(q.poll().toString());

suma=suma+elem;
aux.add(elem);

}
JOptionPane.showMessageDialog(rootPane,
"LA SUMA DE LOS ELEMENTOS DE LA COLA ES: "+suma);

q=aux;
}
ELIMINAR LOS ELEMENTOS IMPARES DE LA COLA
private void
EliminarLosElementosImparesActionPerformed(java.awt.event.ActionEvent evt) {
// ELIMINAR LOS ELEMENTOS IMPARES
int elem;

Queue aux =new LinkedList();

while(!q.isEmpty()){

elem=Integer.parseInt(q.poll().toString());

if(elem%2==0){

aux.add(elem);
}

q=aux;

Mostrar();

También podría gustarte