procesamiento de datos

2
PROCESAMIENTO DE DATOS PILAS Clase Principal package pilas; import java.util.Scanner; public class Pilas { public static void main(String[] args) { Scanner teclado=new Scanner(System.in); Nodo tope=null, aux; char resp; System.out.println("continuar s/n"); resp=teclado.next().charAt(0); while (resp=='s'){ aux=new Nodo(); if (tope==null) aux.antes=null; else aux.antes=tope; teclado.nextLine(); System.out.println("nombre"); aux.nombre=teclado.nextLine();

Upload: jbersosa

Post on 14-Jul-2015

291 views

Category:

Automotive


2 download

TRANSCRIPT

Page 1: Procesamiento de datos

PROCESAMIENTO DE DATOS

PILAS

Clase Principal

package pilas;

import java.util.Scanner;

public class Pilas {

public static void main(String[] args) {

Scanner teclado=new Scanner(System.in);

Nodo tope=null, aux;

char resp;

System.out.println("continuar s/n");

resp=teclado.next().charAt(0);

while (resp=='s'){

aux=new Nodo();

if (tope==null)

aux.antes=null;

else

aux.antes=tope;

teclado.nextLine();

System.out.println("nombre");

aux.nombre=teclado.nextLine();

Page 2: Procesamiento de datos

System.out.println("posicion");

aux.posicion=teclado.nextInt();

tope=aux;

System.out.println("continuar s/n");

resp=teclado.next().charAt(0);

}

while (tope!=null) {

System.out.println("nombre " + tope.nombre + " esta en la posicion

" + tope.posicion);

tope=tope.antes;}

}

}

Clase Nodo

package pilas;

public class Nodo {

protected String nombre;

protected int posicion;

protected Nodo antes; }