package javaapplication1;
/**
*
* @author 225021708
*/
import java.util.Scanner;
import java.util.Stack;
import java.util.Queue;
import java.util.LinkedList;
public class JavaApplication1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int nombres;
String elemento;
Scanner leer = new Scanner(System.in);
Stack <String> pila = new Stack();
Queue <String> cola = new LinkedList();
System.out.print("ingrese la cantidad de nombres:");
nombres = leer.nextInt();
for (int i = 1; i <= nombres; i++) {
System.out.print("ingrese numeros(" + i + "):");
elemento = leer.next();
pila.push(elemento);
cola.add(elemento);
}
System.out.println("nombres de la pila");
for (int j = 1; j <= nombres; j++) {
System.out.println("" + pila.pop());
}
System.out.println("nombres de la cola");
for (int n = 1; n <= nombres; n++) {
System.out.println("" + cola.poll());
}
}
}
No hay comentarios:
Publicar un comentario