New Quicksort Algorithm
This commit is contained in:
parent
137b90efbf
commit
ac83f95054
12
QuickSort/Program.cs
Normal file
12
QuickSort/Program.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace QuickSort
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
65
QuickSort/QuickSort.cs
Normal file
65
QuickSort/QuickSort.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace QuickSort
|
||||
{
|
||||
public class QuickSort
|
||||
{
|
||||
public int[] List { get; set; }
|
||||
|
||||
public QuickSort(int[] List){
|
||||
|
||||
}
|
||||
|
||||
public int[] Sort(){
|
||||
|
||||
Pointer pivot = new Pointer(0, List);
|
||||
|
||||
Pointer left = new Pointer(1, List);
|
||||
|
||||
Pointer right = new Pointer(List.Length-1, List);
|
||||
|
||||
while (right.Index >= left.Index)
|
||||
{
|
||||
while (left.Index <= right.Index && left.Value <= pivot.Value)
|
||||
{
|
||||
left.UpdatePointer(left.Index + 1, List);
|
||||
}
|
||||
while (right.Index >= left.Index & right.Value >= pivot.Value)
|
||||
{
|
||||
right.UpdatePointer(right.Index - 1, List);
|
||||
}
|
||||
if (right.Index > left.Index)
|
||||
{
|
||||
//Swap the values of both
|
||||
swap();
|
||||
}
|
||||
}
|
||||
|
||||
return new int[1]{1};
|
||||
}
|
||||
|
||||
|
||||
public void swap(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class Pointer{
|
||||
public int Index { get; set; }
|
||||
public int Value { get; set; }
|
||||
|
||||
|
||||
public Pointer(int index, int[] list){
|
||||
this.Index = index;
|
||||
this.Value = list[index];
|
||||
}
|
||||
|
||||
public void UpdatePointer(int index, int[] list){
|
||||
this.Index = index;
|
||||
this.Value = list[index];
|
||||
}
|
||||
}
|
||||
}
|
8
QuickSort/QuickSort.csproj
Normal file
8
QuickSort/QuickSort.csproj
Normal file
@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user