Danielos168

Zadanie 2(quicksort)

Nov 21st, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         static int Podzial(string[] T, int l, int p)
  12.         {
  13.             int i, j, klucz, index;            
  14.             string tmp;
  15.             index = p;
  16.             klucz = T[index].Length;
  17.             i = l;
  18.             for (j = l; j < p; j++)
  19.             {
  20.                 if (T[j].Length <= klucz)
  21.                 {
  22.                     tmp = T[i];
  23.                     T[i] = T[j];
  24.                     T[j] = tmp;
  25.                     i++;
  26.                 }
  27.             }
  28.             tmp = T[i];
  29.             T[i] = T[p];
  30.             T[p] = tmp;
  31.             return i;
  32.         }
  33.         static void QuickSort(string[] T, int l, int p)
  34.         {
  35.             if (l >= p)
  36.             {
  37.                 return;
  38.             }
  39.             int i = Podzial(T, l, p);
  40.             QuickSort(T, l, i - 1);
  41.             QuickSort(T, i + 1, p);
  42.         }
  43.         static void Main(string[] args)
  44.         {
  45.             string[] a = { "aa", "aaa", "aaaaaa", "a" };
  46.             QuickSort(a, 0, 3);
  47.             for (int i = 0; i < a.Length; i++)
  48.             {
  49.                 Console.Write(a[i]+", " );
  50.             }
  51.             Console.WriteLine();
  52.             Console.ReadKey();
  53.         }
  54.     }
  55. }
Add Comment
Please, Sign In to add comment