Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace eercicio9
- {
- class Program
- {
- static void Main(string[] args)
- {
- Lista<int> miLista = new Lista<int>();
- Lista<int> multiplos = new Lista<int>();
- Console.WriteLine("Cuantos numeros desea generar?");
- int n = Int32.Parse(Console.ReadLine());
- Random r = new Random();
- for (int i = 0; i < n; i++)
- {
- miLista.AddToLast(r.Next(10, 99));
- }
- Console.WriteLine("\nLista Inicial");
- foreach (int value in miLista)
- {
- Console.WriteLine("|_{0}_|", value);
- if ((value % 6) == 0)
- {
- multiplos.AddToLast(value);
- }
- }
- if (multiplos.Empty)
- {
- Console.WriteLine("\nNo se encontraron mΓΊltiplos de 6");
- }
- else
- {
- Console.WriteLine("\nLista Multiplos de 6");
- foreach (int value in multiplos)
- {
- Console.WriteLine("|_{0}_|", value);
- }
- }
- Console.ReadKey();
- }
- }
- }
- /*-----------------------------------------------------------------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Collections;
- using System.Text;
- namespace eercicio9
- {
- class Lista<E> : IEnumerable where E : IComparable
- {
- private Node head;
- private int count;
- private Node tail;
- public bool Empty
- {
- get { return this.count <= 0; }
- }
- public Lista()
- {
- this.head = null;
- this.count = 0;
- this.tail = null;
- }
- public void AddToLast(E item)
- {
- Node temp = new Node(item, null);
- if (Empty)
- {
- this.head = temp;
- }
- else
- {
- this.tail.next = temp;
- }
- this.tail = temp;
- ++this.count;
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- return MyEnumerator();
- }
- private IEnumerator MyEnumerator()
- {
- for (Node skip = head; skip != null; skip = skip.Next)
- {
- yield return skip.Item;
- }
- }
- //-----------------------------------------------------------------------------------------------------------------------------
- private class Node
- {
- public E item;
- public Node next;
- public Node()
- {
- }
- public Node(E item)
- {
- this.item = item;
- }
- public Node(E item, Node next)
- {
- this.item = item;
- this.next = next;
- }
- public Node(Node next)
- {
- this.next = next;
- }
- public Node Next
- {
- get { return this.next; }
- set { this.next = value; }
- }
- public E Item
- {
- get { return this.item; }
- set { this.item = value; }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement