Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class GenericList<T>where T : IComparable<T>
- {
- private List<T> data;
- public int ListSize => this.data.Count;
- public int Count { get;private set; }
- public GenericList()
- {
- this.data=new List<T>();
- }
- private T Current { get; set; }
- // void Add(T element)
- // T Remove(int index)
- // bool Contains(T element)
- // void Swap(int index1, int index2)
- // int CountGreaterThan(T element)
- // T Max()
- // T Min()
- public void Add(T t)
- {
- this.Count++;
- this.Current = t;
- this.data.Add(Current);
- }
- public void Remove(int index)
- {
- this.Current = data[index];
- data.Remove(Current);
- this.Count--;
- }
- public bool Contains(T t)
- {
- bool truth = this.data.Contains(t);
- return truth;
- }
- public void Swap(int index1, int index2)
- {
- this.Current = this.data[index1];
- var keeper = this.data[index2];
- this.data[index2] = this.Current;
- this.data[index1] = keeper;
- }
- public int CounteGreaterThan(T t)
- {
- int count = 0;
- foreach (var generic in this.data)
- {
- if (generic.CompareTo(t) > 0)
- {
- count++;
- }
- }
- return count;
- }
- public T Max()
- {
- var maxT = this.data.Max();
- return maxT;
- }
- public T Min()
- {
- var minT = this.data.Min();
- return minT;
- }
- public void Sort()
- {
- this.data.OrderByDescending(x => x);
- }
- public void Print()
- {
- foreach (var variables in this.data)
- {
- Console.WriteLine(variables);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment