SHARE
TWEET

Untitled

a guest Sep 16th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace quick_sort
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] array = { 3, 4, 2, 1, 0, 5, 32, 5, 23 };
  14.             quicksort(array, 0, array.Length - 1);
  15.             foreach (var e in array)
  16.                 Console.WriteLine(e);
  17.             Console.ReadKey();
  18.         }
  19.  
  20.         static int partition(int[] array,  int start, int end)
  21.         {
  22.             int temp, marker = start;
  23.             for (int i = start; i < end; i++)
  24.                 if (array[i] < array[end])
  25.                 {
  26.                     temp = array[marker];
  27.                     array[marker] = array[i];
  28.                     array[i] = temp;
  29.                     marker++;
  30.                 }
  31.             temp = array[marker];
  32.             array[marker] = array[end];
  33.             array[end] = temp;
  34.             return marker;
  35.         }
  36.  
  37.         static void quicksort(int[] array, int start, int end)
  38.         {
  39.             if (start >= end)
  40.                 return;
  41.             int pivot = partition(array, start, end);
  42.             quicksort(array, start, pivot - 1);
  43.             quicksort(array, pivot + 1, end);
  44.         }
  45.     }
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top