Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- class Program
- {
- static int Podzial(string[] T, int l, int p)
- {
- int i, j, klucz, index;
- string tmp;
- index = p;
- klucz = T[index].Length;
- i = l;
- for (j = l; j < p; j++)
- {
- if (T[j].Length <= klucz)
- {
- tmp = T[i];
- T[i] = T[j];
- T[j] = tmp;
- i++;
- }
- }
- tmp = T[i];
- T[i] = T[p];
- T[p] = tmp;
- return i;
- }
- static void QuickSort(string[] T, int l, int p)
- {
- if (l >= p)
- {
- return;
- }
- int i = Podzial(T, l, p);
- QuickSort(T, l, i - 1);
- QuickSort(T, i + 1, p);
- }
- static void Main(string[] args)
- {
- string[] a = { "aa", "aaa", "aaaaaa", "a" };
- QuickSort(a, 0, 3);
- for (int i = 0; i < a.Length; i++)
- {
- Console.Write(a[i]+", " );
- }
- Console.WriteLine();
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment