Advertisement
Montoya-Romina-Anahi

Tp4_Punto5_ListaSimple

Jun 19th, 2020
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. public class listaSimple {
  2. nodo primero;
  3.  
  4. nodo ultimo;
  5.  
  6. public listaSimple() {
  7.  
  8. primero=null;
  9.  
  10. ultimo=null;
  11.  
  12. }
  13.  
  14. public void ingresarNodo(int dato) {
  15.  
  16. nodo nodoNuevo= new nodo();
  17.  
  18. nodoNuevo.dato=dato;
  19.  
  20. if (primero==null) {
  21.  
  22. primero=nodoNuevo;
  23.  
  24. primero.siguiente=null;
  25.  
  26. ultimo=primero;
  27.  
  28. }else {
  29.  
  30. ultimo.siguiente=nodoNuevo;
  31.  
  32. nodoNuevo.siguiente=null;
  33.  
  34. ultimo=nodoNuevo;
  35.  
  36. }
  37.  
  38. }
  39.  
  40. public void verLista() {
  41.  
  42. nodo actual=new nodo();
  43.  
  44. actual=primero;
  45.  
  46. while (actual!=null) {
  47.  
  48. System.out.println(actual.dato);
  49.  
  50. actual=actual.siguiente;
  51.  
  52. }
  53.  
  54. }
  55.  
  56. public void verListamultiple() {
  57.  
  58. nodo actual=new nodo();
  59.  
  60. actual=primero;
  61.  
  62. while (actual!=null) {
  63.  
  64. if (actual.dato%2==0 && actual.dato%5==0 ) {
  65.  
  66. System.out.println(actual.dato);
  67.  
  68. actual=actual.siguiente;
  69.  
  70. }
  71.  
  72. else {
  73.  
  74. actual=actual.siguiente;
  75.  
  76. }
  77.  
  78. }
  79.  
  80. }
  81.  
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88. import java.util.Scanner;
  89.  
  90. import java.util.Random;
  91.  
  92.  
  93. public class main {
  94.  
  95. public static void main(String[] args) {
  96.  
  97. int elemento;
  98.  
  99. Random r =new Random();
  100.  
  101. Scanner S= new Scanner(System.in);
  102.  
  103. listaSimple L = new listaSimple();
  104.  
  105. System.out.println("Ingrese la cantidad de elementos : ");
  106.  
  107. elemento=S.nextInt();
  108.  
  109. for (int i=0;i<elemento;++i) {
  110.  
  111. L.ingresarNodo(r.nextInt(30));
  112.  
  113. }
  114.  
  115. System.out.println("Lista original");
  116.  
  117. L.verLista();
  118.  
  119. System.out.println("Lista multiplo 2 y 5 a la vez");
  120.  
  121. L.verListamultiple();
  122.  
  123. }
  124.  
  125. }
  126.  
  127.  
  128.  
  129.  
  130.  
  131. public class nodo {
  132. int dato;
  133.  
  134. nodo siguiente;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement