Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using BenchmarkDotNet.Attributes;
- namespace Task4C
- {
- [MemoryDiagnoser]
- public class QuickSort
- {
- private int[] _numbers;
- int Partition (int[] array, int start, int end)
- {
- int marker = start;
- for ( int i = start; i <= end; i++ )
- {
- if ( array[i] <= array[end] )
- {
- (array[marker], array[i]) = (array[i], array[marker]);
- marker += 1;
- }
- }
- return marker - 1;
- }
- private void Sort (int[] array, int start, int end)
- {
- if ( start >= end )
- {
- return;
- }
- int pivot = Partition (array, start, end);
- Sort(array, start, pivot-1);
- Sort(array, pivot+1, end);
- }
- [Benchmark]
- public void ArraySort()
- {
- Sort(_numbers, 0, _numbers.Length - 1);
- }
- [IterationSetup]
- public void MakeArray()
- {
- var number = new Random();
- var arr = new int[2000];
- for (var i = 0; i < arr.Length; i++) {
- arr[i] = number.Next();
- }
- _numbers = arr;
- }
- }
- }
Add Comment
Please, Sign In to add comment