Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
QuickSort
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here Console.WriteLine("Hello, world!"); List<int> unsortedArray = new List<int> { 1, 10, 5, 3, 2, 8, 8, 0 }; List<int> sortedArray; sortedArray = myQuickSort(unsortedArray); foreach (int item in sortedArray) { Console.WriteLine(item); } Console.Read(); } public static List<int> myQuickSort(List<int> unsortedArray) { if (unsortedArray.Count <= 1) { return unsortedArray; } else { List<int> leftPartition; List<int> rightPartition; createPartion(unsortedArray, out leftPartition, out rightPartition); List<int> sortedArrayLeft; List<int> sortedArrayRight; sortedArrayLeft = myQuickSort(leftPartition); sortedArrayRight = myQuickSort(rightPartition); //return leftPartition.Concat(rightPartition).ToArray(); //List<int> sortedList = new List<int>(); sortedArrayLeft.Add(unsortedArray[0]); sortedArrayLeft.AddRange(sortedArrayRight); return sortedArrayLeft; } } public static void createPartion(List<int> unsortedArray, out List<int> leftPartition, out List<int> rightPartition) { int sizeOfUnsortedArray = unsortedArray.Count(); int pivot = unsortedArray[0]; int currentIndextInTheArray = 1; leftPartition = new List<int>(); rightPartition = new List<int>(); //leftPartition = new int []; for (currentIndextInTheArray = 1; currentIndextInTheArray < sizeOfUnsortedArray; currentIndextInTheArray++) { if (unsortedArray[currentIndextInTheArray] < pivot) { leftPartition.Add(unsortedArray[currentIndextInTheArray]); } else { rightPartition.Add(unsortedArray[currentIndextInTheArray]); } } } } }
run
|
edit
|
history
|
help
0
Testing for Integers and Floats in a String
New House Exam 11 April
DN
Reverse Array
Daily Coding Problem: Problem #4
Get a webpage - the sync way
Program A
Overloading Unary operator ~ (to reverse the string)
Palindrome String
Testing