Advertisement
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;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void swap(int v1, int v2)
- {
- v1 = (v1 + v2);
- v2 = (v1 - v2);
- v1 = (v1 - v2);
- }
- static void simple_sort(int n, byte[] t)
- {
- for (byte i = 0; i <= n - 2; i++)
- {
- for (byte z = (byte)(i + 1); z <= n - 1; z++)
- {
- if (t[i] > t[z])
- {
- byte swap;
- swap = t[i];
- t[i] = t[z];
- t[z] = swap;
- }
- }
- }
- }
- static void minimumselect_sort(int n, byte[] t)
- {
- for (byte i = 0; i <= n - 2; i++)
- {
- byte min = i;
- for (byte z = (byte)(i + 1); z <= n - 1; z++)
- {
- if (t[min] > t[z]) min = z;
- }
- byte swap;
- swap = t[i];
- t[i] = t[min];
- t[min] = swap;
- }
- }
- static void bubble_sort(int n, byte[] t)
- {
- for (byte i = (byte)n; i > 1; i--)
- {
- for (byte z = 0; z < i - 1; z++)
- {
- if (t[z] > t[z + 1])
- {
- byte swap;
- swap = t[z];
- t[z] = t[z + 1];
- t[z + 1] = swap;
- }
- }
- }
- }
- static void fixed_bubble_sort(int n, byte[] t)
- {
- byte i = (byte)(n-1);
- //for (; i >= 1; )
- while (i >= 1)
- {
- byte sn = 0;
- for (byte z = 0; z < i; z++)
- {
- if (t[z] > t[z + 1])
- {
- byte swap; swap = t[z]; t[z] = t[z + 1]; t[z + 1] = swap;
- sn = z;
- }
- }
- i = sn;
- }
- }
- static void fixed_beill(int n, byte[] t)
- {
- for (byte i = 1; i < n; i++)
- {
- sbyte j = (sbyte)(i - 1);
- byte y = t[i];
- while (j >= 0 && t[j] > y)
- {
- t[j + 1] = t[j];
- j--;
- }
- t[j + 1] = y;
- }
- }
- static void sort_beszuras(int n, byte[] t)
- {
- for (int i = 1; i < n; i++)
- {
- int kulcs = t[i];
- int j = i - 1;
- while (j >= 0 && t[j] > kulcs)
- {
- t[j + 1] = t[j];
- j--;
- }
- t[j + 1] = (byte)kulcs;
- }
- }
- static void quick_sort(int l, int r, byte[] t)
- {
- int i = l, j = r;
- byte tmp;
- int pivot = t[(l + (r)) / 2];
- /* partition */
- while (i <= j)
- {
- while (t[i] < pivot) i++;
- while (t[j] > pivot) j--;
- if (i <= j)
- {
- tmp = t[i];
- t[i] = t[j];
- t[j] = tmp;
- i++;
- j--;
- }
- };
- /* recursion */
- if (l < j)
- quick_sort(l, j, t);
- if (i < r)
- quick_sort(i, r, t);
- }
- static void quick_sort_string(int l, int r, string[] t)
- {
- int i = l, j = r;
- string tmp;
- string pivot = t[(l + (r)) / 2];
- /* partition */
- while (i <= j)
- {
- while (t[i].CompareTo(pivot) < 0) i++;
- while (t[j].CompareTo(pivot) > 0) j--;
- if (i <= j)
- {
- tmp = t[i];
- t[i] = t[j];
- t[j] = tmp;
- i++;
- j--;
- }
- };
- /* recursion */
- if (l < j)
- quick_sort_string(l, j, t);
- if (i < r)
- quick_sort_string(i, r, t);
- }
- static void Main(string[] args)
- {
- //byte[] array = new byte[15]{6,5,4,3,2,1,32,63,94,1,2,3,46,157,35};
- string[] array = new string[] { "álmos", "előd", "ond", "kond", "tas", "huba", "töhötöm" };
- //simple_sort(array.Length, array);
- //minimumselect_sort(array.Length, array);
- //bubble_sort(array.Length, array);
- //fixed_bubble_sort(array.Length, array);
- //fixed_beill(array.Length, array);
- //sort_beszuras(array.Length, array);
- //quick_sort(0, array.Length-1, array);
- quick_sort_string(0, array.Length - 1, array);
- Console.Write("\n");
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement