Advertisement
silvi81

09.CollectionHierarchy

Jul 25th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _09.CollectionHierarchy
  8. {
  9.     public class AddCollection
  10.     {
  11.         public AddCollection()
  12.         {
  13.             this.List= new List<string>();
  14.         }
  15.         public List<string> List { get; set; }
  16.  
  17.         public int Add(string value)
  18.         {
  19.             int index = this.List.Count;
  20.             this.List.Add(value);
  21.             return index;
  22.         }
  23.     }
  24.  
  25.     public class AddRemoveCollection
  26.     {
  27.         public AddRemoveCollection()
  28.         {
  29.             this.List = new List<string>();
  30.         }
  31.         public List<string> List { get; set; }
  32.  
  33.         public int Add(string value)
  34.         {
  35.             this.List.Insert(0, value);
  36.             return 0;
  37.         }
  38.  
  39.         public string Remove()
  40.         {
  41.             string removed = List[this.List.Count - 1];
  42.             this.List.RemoveAt(this.List.Count - 1);
  43.  
  44.             return removed;
  45.         }
  46.     }
  47.  
  48.     public class MyList
  49.     {
  50.         public MyList()
  51.         {
  52.             this.List = new List<string>();
  53.         }
  54.         public List<string> List { get; set; }
  55.  
  56.         public int Add(string value)
  57.         {
  58.             this.List.Insert(0, value);
  59.  
  60.             return 0;
  61.         }
  62.  
  63.         public string Remove()
  64.         {
  65.             string removed = List[0];
  66.             this.List.RemoveAt(0);
  67.  
  68.             return removed;
  69.         }
  70.  
  71.         public int Used { get { return this.List.Count; } }
  72.     }
  73.  
  74.     class Program
  75.     {
  76.         static void Main(string[] args)
  77.         {
  78.             string[] tokens = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  79.  
  80.             AddCollection addCollection = new AddCollection();
  81.             AddRemoveCollection removeCollection = new AddRemoveCollection();
  82.             MyList myList = new MyList();
  83.  
  84.             foreach (var str in tokens)
  85.             {
  86.                 Console.Write(addCollection.Add(str));
  87.                 Console.Write(" ");
  88.             }
  89.  
  90.             Console.WriteLine();
  91.  
  92.             foreach (var str in tokens)
  93.             {
  94.                 Console.Write(removeCollection.Add(str));
  95.                 Console.Write(" ");
  96.             }
  97.  
  98.             Console.WriteLine();
  99.  
  100.             foreach (var str in tokens)
  101.             {
  102.                 Console.Write(myList.Add(str));
  103.                 Console.Write(" ");
  104.             }
  105.             Console.WriteLine();
  106.  
  107.             int count = int.Parse(Console.ReadLine());
  108.  
  109.             for (int i = 0; i < count; i++)
  110.             {
  111.                 Console.Write(removeCollection.Remove());
  112.                 Console.Write(" ");
  113.             }
  114.  
  115.             Console.WriteLine();
  116.  
  117.             for (int i = 0; i < count; i++)
  118.             {
  119.                 Console.Write(myList.Remove());
  120.                 Console.Write(" ");
  121.             }
  122.         }
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement