Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lista.enlazada1;
- import java.util.Scanner;
- public class ListaEnlazada1 {
- public String marca;
- public String modelo;
- public int kilometraje;
- public ListaEnlazada1 nodosiguiente;
- public static void main(String[] args) {
- /* enter the number of nodes to be created */
- Scanner leer= new Scanner(System.in);
- System.out.println("Digite la cantidad de nodos a ingresar)");
- int n,contador=0;
- n=leer.nextInt();
- /* the three data of the node is entered */
- for (int i =1; i <= n; i++){
- ListaEnlazada1 nodo = new ListaEnlazada1();
- System.out.print("ingrese la marca ");
- nodo.marca=leer.next();
- System.out.print("ingrese el modelo ");
- nodo.modelo=leer.next();
- System.out.print("ingrese el kilometraje ");
- nodo.kilometraje=leer.nextInt();
- /* the node is created */
- if(contador==0){
- nodo.nodosiguiente = null;
- contador ++;
- } else {
- nodo.nodosiguiente = nodo;
- contador ++;
- }
- /* nodes are printed */
- for ( i =1; i <= n; i++){
- System.out.println("marca " +nodo.marca+ "n");
- System.out.println("modelo " +nodo.modelo+ "n");
- System.out.println("kilometraje " +nodo.kilometraje+ "n");
- System.out.println("apuntador " +nodo.nodosiguiente + "n");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment