Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Con libreria linkedList, queue.
- package eje2;
- import java.util.LinkedList;
- import java.util.Queue;
- import java.util.Scanner;
- import colaCircular.colaCircular;
- public class eje2 {
- public static Queue<Integer> quitarRepetido(Queue<Integer> cola,int aux) throws Exception{
- Queue<Integer> listaColaAux = new LinkedList<Integer>();
- for(int i =0;i<cola.size();i++) {
- if (!cola.isEmpty()){
- int ayuda=cola.poll();
- if(ayuda!=aux) {
- listaColaAux.add(ayuda);
- }
- }else throw new Exception("Cola vacia ");
- }
- System.out.print(listaColaAux);
- System.out.println(" ");
- return listaColaAux;
- }
- public static void main(String[] args) throws Exception {
- Queue<Integer> numeros = new LinkedList<Integer>();
- Scanner lectura= new Scanner(System.in);
- char resp=' ';
- while(resp!='n') {
- System.out.println("Ingrese numeros a almacenar en la cola: ");
- int num=lectura.nextInt();
- numeros.add(num);
- System.out.println("Desea ingresar mas elementos a la cola?(s/n)");
- resp= lectura.next().charAt(0);
- }
- System.out.println("Ingrese numero a quitar: ");
- int repetido=lectura.nextInt();
- System.out.println("Elemento sin repetir: "+quitarRepetido(numeros,repetido));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement