gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
hi
- User
hi
- Assistant
Hello! How can I assist you today?
- User
write quick sort by C#
- Assistant
Certainly! Here's an implementation of the Quick Sort algorithm in C#:
using System; class QuickSort { static void Main(string[] args) { int[] arr = { 9, 5, 7, 2, 1, 6, 3, 8, 4 }; Console.WriteLine("Unsorted Array: "); PrintArray(arr); Console.WriteLine(); QuickSortAlgorithm(arr, 0, arr.Length - 1); Console.WriteLine("Sorted Array: "); PrintArray(arr); } static void QuickSortAlgorithm(int[] arr, int low, int high) { if (low < high) { int partitionIndex = Partition(arr, low, high); QuickSortAlgorithm(arr, low, partitionIndex - 1); QuickSortAlgorithm(arr, partitionIndex + 1, high); } } static int Partition(int[] arr, int low, int high) { int pivot = arr[high]; int i = low - 1; for (int j = low; j < high; j++) { if (arr[j] < pivot) { i++; int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } int temp1 = arr[i + 1]; arr[i + 1] = arr[high]; arr[high] = temp1; return i + 1; } static void PrintArray(int[] arr) { foreach (int value in arr) { Console.Write(value + " "); } Console.WriteLine(); } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.