Advertisement
damarijsilva

ejercicio9

Oct 13th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace eercicio9
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Lista<int> miLista = new Lista<int>();
  13.             Lista<int> multiplos = new Lista<int>();
  14.             Console.WriteLine("Cuantos numeros desea generar?");
  15.             int n = Int32.Parse(Console.ReadLine());
  16.             Random r = new Random();
  17.  
  18.             for (int i = 0; i < n; i++)
  19.             {
  20.                 miLista.AddToLast(r.Next(10, 99));
  21.             }
  22.  
  23.  
  24.             Console.WriteLine("\nLista Inicial");
  25.             foreach (int value in miLista)
  26.             {
  27.                 Console.WriteLine("|_{0}_|", value);
  28.                 if ((value % 6) == 0)
  29.                 {
  30.                     multiplos.AddToLast(value);
  31.                 }
  32.             }
  33.  
  34.             if (multiplos.Empty)
  35.             {
  36.                 Console.WriteLine("\nNo se encontraron mΓΊltiplos de 6");
  37.             }
  38.             else
  39.             {
  40.                 Console.WriteLine("\nLista Multiplos de 6");
  41.                 foreach (int value in multiplos)
  42.                 {
  43.                     Console.WriteLine("|_{0}_|", value);
  44.                 }
  45.  
  46.             }
  47.             Console.ReadKey();
  48.         }
  49.     }
  50. }
  51.  
  52. /*-----------------------------------------------------------------------------------------------------------------------------------*/
  53. using System;
  54. using System.Collections.Generic;
  55. using System.Linq;
  56. using System.Collections;
  57. using System.Text;
  58.  
  59. namespace eercicio9
  60. {
  61.     class Lista<E> : IEnumerable where E : IComparable
  62.     {
  63.         private Node head;
  64.         private int count;
  65.         private Node tail;
  66.  
  67.         public bool Empty
  68.         {
  69.             get { return this.count <= 0; }
  70.  
  71.         }
  72.  
  73.         public Lista()
  74.         {
  75.             this.head = null;
  76.             this.count = 0;
  77.             this.tail = null;
  78.         }
  79.  
  80.  
  81.         public void AddToLast(E item)
  82.         {
  83.             Node temp = new Node(item, null);
  84.             if (Empty)
  85.             {
  86.                 this.head = temp;
  87.             }
  88.             else
  89.             {
  90.                 this.tail.next = temp;
  91.             }
  92.             this.tail = temp;
  93.             ++this.count;
  94.         }
  95.      
  96.         IEnumerator IEnumerable.GetEnumerator()
  97.         {
  98.             return MyEnumerator();
  99.         }
  100.  
  101.         private IEnumerator MyEnumerator()
  102.         {
  103.             for (Node skip = head; skip != null; skip = skip.Next)
  104.             {
  105.                 yield return skip.Item;
  106.             }
  107.         }
  108.  
  109.  
  110.         //-----------------------------------------------------------------------------------------------------------------------------
  111.  
  112.         private class Node
  113.         {
  114.             public E item;
  115.             public Node next;
  116.  
  117.             public Node()
  118.             {
  119.             }
  120.  
  121.             public Node(E item)
  122.             {
  123.                 this.item = item;
  124.             }
  125.  
  126.             public Node(E item, Node next)
  127.             {
  128.                 this.item = item;
  129.                 this.next = next;
  130.             }
  131.  
  132.             public Node(Node next)
  133.             {
  134.                 this.next = next;
  135.             }
  136.  
  137.             public Node Next
  138.             {
  139.                 get { return this.next; }
  140.                 set { this.next = value; }
  141.             }
  142.  
  143.             public E Item
  144.             {
  145.                 get { return this.item; }
  146.                 set { this.item = value; }
  147.             }
  148.         }
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement