123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace SORTER
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- int[] array = new int[100] { 1, 5, 4, 3, 2, 6, 8, 7, 10, 9, 11, 15, 13, 12, 14, 18, 16, 17, 19, 23, 21, 20, 22, 30, 43, 53, 23, 26, 78, 28, 15, 90, 99, 22, 76, 55, 68, 23, 54, 43, 46, 41, 51, 59, 91, 5, 3, 16, 17, 29, 34, 36, 76, 88, 84, 43, 95, 93, 23, 67, 64, 34, 38, 32, 23, 26, 84, 89, 94, 97, 12, 3, 5, 8, 9, 54, 67, 76, 72, 12, 16, 17, 18, 20, 33, 1, 32, 86, 98, 32, 24, 27, 19, 87, 98, 43, 29, 98, 78, 82};
- public MainWindow()
- {
- InitializeComponent();
- //linearSelectionSort();
- //methodMinMax();
- //BubbleSort();
- ShuttleSort();
- }
- void linearSelectionSort()
- {
- List<int> arraySorted = new List<int>();
- int max = int.MinValue;
- int index = 0;
- while (arraySorted.Count < 100)
- {
- for (int i = 0; i < array.Length; ++i)
- {
- if (max <= array[i] && array[i] != 100)
- {
- max = array[i];
- index = i;
- }
- }
- array[index] = 100;
- arraySorted.Add(max);
- max = int.MinValue;
- }
- string foo = "";
- for (int i = 0; i < arraySorted.Count; ++i)
- {
- foo += arraySorted[i].ToString() + " ";
- }
- MessageBox.Show(foo);
- }
- void methodMinMax()
- {
- for (int i = 0; i < array.Length - 1; ++i)
- {
- int max = i;
- for (int j = i + 1; j < array.Length; ++j)
- {
- if (array[j].CompareTo(array[max]) > 0)
- {
- max = j;
- }
- }
- int temp = array[i];
- array[i] = array[max];
- array[max] = temp;
- }
- string foo = "";
- for (int i = 0; i < array.Length; ++i)
- {
- foo += array[i] + " ";
- }
- MessageBox.Show(foo);
- }
- void BubbleSort()
- {
- int temp = 0;
- for (int i = 0; i < array.Length - 1; i++)
- {
- for (int j = 0; j < array.Length - i - 1; j++)
- {
- if (array[j + 1] < array[j])
- {
- temp = array[j + 1];
- array[j + 1] = array[j];
- array[j] = temp;
- }
- }
- }
- string foo = "";
- for (int i = 0; i < array.Length; ++i)
- {
- foo += array[i] + " ";
- }
- MessageBox.Show(foo);
- }
- void ShuttleSort()
- {
- int temp = 0;
- for (int i = 0; i < array.Length - 1; i++)
- {
- for (int j = 0; j < array.Length - i - 1; j++)
- {
- if (array[j + 1] < array[j])
- {
- temp = array[j + 1];
- array[j + 1] = array[j];
- array[j] = temp;
- }
- }
- }
- string foo = "";
- for (int i = 0; i < array.Length; ++i)
- {
- foo += array[i] + " ";
- }
- MessageBox.Show(foo);
- }
- }
- }
|