Quick Sort Creates Stackoverflow
By : andych
Date : March 29 2020, 07:55 AM
will help you Well. Your code will recurse between log2 10000000 and 10000000 levels deep. Depending on tail-recursion optimizations in the compiler (if any) that can use a lot of stackspace.
|
How can i sort two integer arrays parallel with quick sort in C#?
By : user3370416
Date : March 29 2020, 07:55 AM
will help you I want to sort two arrays simultaneously. I am beginner in Parallelizing in c# and i want to know how i should do it, by Multithreading or something like that... , Sort both of these "simultaneously". code :
System.Threading.Tasks.Task.Run(() => quick_sort(a1,0,100));
System.Threading.Tasks.Task.Run(() => quick_sort(a2,0,100));
|
How do I modify my Quick Sort Algorithm so that it can sort Double data type arrays?
By : alexander cayetano
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You should be able to use generics, where the type implements IComparable , so that you can compare the items (you can't use < or > operators on generic types). This should do the trick: code :
public static void QuickSort<T>(T[] data) where T:IComparable<T>
{
Quick_Sort(data, 0, data.Length - 1);
}
public static void Quick_Sort<T>(T[] data, int left, int right) where T:IComparable<T>
{
int i, j;
T pivot, temp;
i = left;
j = right;
pivot = data[(left + right) / 2];
do
{
while ((data[i].CompareTo(pivot) < 0) && (i < right)) i++;
while ((pivot.CompareTo(data[j]) < 0) && (j > left)) j--;
if (i <= j)
{
temp = data[i];
data[i] = data[j];
data[j] = temp;
i++;
j--;
}
} while (i <= j);
if (left < j) Quick_Sort(data, left, j);
if (i < right) Quick_Sort(data, i, right);
}
|
How can I make my Quick Sort Algorithm sort the arrays in both Ascending and Descending order?
By : Anon Ymous
Date : March 29 2020, 07:55 AM
I wish this helpful for you You can change your Quicksort method to accept an IComparer comparer, and then use that to make the comparisons. Then you can use Comparer.Default if you want the default comparison order, or you can use Comparer.Create() to create a custom (e.g. reversed) comparison. code :
using System;
using System.Collections.Generic;
namespace ConsoleApp1
{
class Program
{
static void Main()
{
int[] data = {6, 7, 2, 3, 8, 1, 9, 0, 5, 4};
QuickSort(data);
Console.WriteLine(string.Join(", ", data)); // Prints 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
QuickSort(data, Comparer<int>.Create((a, b) => b.CompareTo(a)));
Console.WriteLine(string.Join(", ", data)); // Prints 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
}
public static void QuickSort<T>(T[] data)
{
Quick_Sort(data, 0, data.Length - 1, Comparer<T>.Default);
}
public static void QuickSort<T>(T[] data, IComparer<T> comparer)
{
Quick_Sort(data, 0, data.Length - 1, comparer);
}
public static void Quick_Sort<T>(T[] data, int left, int right, IComparer<T> comparer)
{
int i, j;
T pivot, temp;
i = left;
j = right;
pivot = data[(left + right) / 2];
do
{
while ( (comparer.Compare(data[i], pivot) < 0) && (i < right)) i++;
while ( (comparer.Compare(pivot, data[j]) < 0) && (j > left)) j--;
if (i <= j)
{
temp = data[i];
data[i] = data[j];
data[j] = temp;
i++;
j--;
}
} while (i <= j);
if (left < j) Quick_Sort(data, left, j, comparer);
if (i < right) Quick_Sort(data, i, right, comparer);
}
}
}
|
Quick Sort in Scala vs. java.util.Arrays.sort
By : ketakers
Date : March 29 2020, 07:55 AM
This might help you You comapared a highly optimized implementation of a generic sorting algorithm (java.util.Arrays.sort) to a handrolled implementation without optimization (your Scala code). Thus it is bound to be slower.
|