Aliendreamer

generics

Mar 27th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.  
  6.  
  7. public class GenericList<T>where T : IComparable<T>
  8. {
  9.     private List<T> data;
  10.  
  11.     public int ListSize => this.data.Count;
  12.  
  13.     public int Count { get;private set; }
  14.  
  15.     public GenericList()
  16.     {
  17.         this.data=new List<T>();
  18.     }
  19.  
  20.     private T Current { get; set; }
  21.  
  22.     //      void Add(T element)
  23.     //      T Remove(int index)
  24.     //      bool Contains(T element)
  25.     //      void Swap(int index1, int index2)
  26.     //      int CountGreaterThan(T element)
  27.     //      T Max()
  28.     //      T Min()
  29.  
  30.     public void Add(T t)
  31.     {
  32.         this.Count++;
  33.        this.Current = t;
  34.        this.data.Add(Current);
  35.     }
  36.     public  void  Remove(int index)
  37.     {
  38.         this.Current = data[index];
  39.         data.Remove(Current);
  40.         this.Count--;
  41.     }
  42.  
  43.     public bool Contains(T t)
  44.     {
  45.         bool truth = this.data.Contains(t);
  46.         return truth;
  47.     }
  48.  
  49.     public void Swap(int index1, int index2)
  50.     {
  51.         this.Current = this.data[index1];
  52.         var keeper = this.data[index2];
  53.         this.data[index2] = this.Current;
  54.         this.data[index1] = keeper;
  55.     }
  56.  
  57.     public int CounteGreaterThan(T t)
  58.     {
  59.         int count = 0;
  60.         foreach (var generic in this.data)
  61.         {
  62.             if (generic.CompareTo(t) > 0)
  63.             {
  64.                 count++;
  65.             }
  66.         }
  67.  
  68.         return count;
  69.     }
  70.  
  71.     public T Max()
  72.     {
  73.         var maxT = this.data.Max();
  74.         return maxT;
  75.     }
  76.     public T Min()
  77.     {
  78.         var minT = this.data.Min();
  79.         return minT;
  80.     }
  81.  
  82.     public void Sort()
  83.     {
  84.         this.data.OrderByDescending(x => x);
  85.     }
  86.  
  87.     public void Print()
  88.     {
  89.         foreach (var variables in this.data)
  90.         {
  91.             Console.WriteLine(variables);
  92.         }
  93.     }
  94.    
  95. }
Advertisement
Add Comment
Please, Sign In to add comment