using System; public class Test { public static void Main() { var unsorted = Console.ReadLine().Split(' '); int[] a = Array.ConvertAll(unsorted,x=>int.Parse(x)); int n= a.Length; Quicksort(a,0,n-1); for(int i=0;i<n;i++) { Console.WriteLine(a[i]); } } public static void Quicksort(int[] a,int low,int high) { if(low<high) { int pi= Partition(a,low,high); Quicksort(a,low,pi-1); Quicksort(a,pi+1,high); } } public static int Partition(int[]a,int low,int high) { int pivot = a[high]; int i = low-1; for(int j=low;j<=high-1;j++) { if(a[j]<pivot) { i++; int temp=a[i]; a[i]=a[j]; a[j]=temp; } } int temp2 = a[high]; a[high]=a[i+1]; a[i+1]=temp2; return i+1; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Merge_sort { class Program { static void Main(string[] args) { int T = Convert.ToInt32(Console.ReadLine()); while(T>0) { int a; List<int> unsorted = new List<int>(); List<int> sorted; var s = Console.ReadLine().Split(' '); for(int i=0;i<s.Length;i++) { if(int.TryParse(s[i],out a)) { unsorted.Add(a); } } Console.WriteLine("Original array elements:" ); for(int i = 0; i< unsorted.Count;i++){ Console.Write(unsorted[i]+" "); } Console.WriteLine(); sorted = MergeSort(unsorted); Console.WriteLine("Sorted array elements: &q