StackOverFlowException
class Program { static void Main(string[] args) { int x = 3; List<int> num = new List<int>(); Random rnd = new Random(); for (int i = 0; i < x; i++) { num.Add(rnd.Next(99)); } Sort s = new Sort(); int q = 1, w = 0; s.QuickSort<int>(num); } } public class Sort { public Sort() { } public void QuickSort<T>(List<T> Tlist) where T : IComparable { List<T> tmp = QuickSortHelper(Tlist); Tlist.Clear(); foreach (T t in tmp) Tlist.Add(t); } public List<T> QuickSortHelper<T>(List<T> Tlist) where T : IComparable { List<T> left= new List<T>(), right = new List<T>(), returList = new List<T>(); if (Tlist.Count <= 1) return Tlist; int x =Tlist.Count-1; T pivot = Tlist[x]; foreach (T t in Tlist) if (t.CompareTo(pivot) == -1) left.Add(t); else right.Add(t); foreach(T t in QuickSortHelper<T>(left)) returList.Add(t); returList.Add(pivot); foreach (T t in QuickSortHelper<T>(right)) returList.Add(t); return returList; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)