MainWindow.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace SORTER
  16. {
  17. /// <summary>
  18. /// Interaction logic for MainWindow.xaml
  19. /// </summary>
  20. public partial class MainWindow : Window
  21. {
  22. 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};
  23. public MainWindow()
  24. {
  25. InitializeComponent();
  26. //linearSelectionSort();
  27. //methodMinMax();
  28. //BubbleSort();
  29. ShuttleSort();
  30. }
  31. void linearSelectionSort()
  32. {
  33. List<int> arraySorted = new List<int>();
  34. int max = int.MinValue;
  35. int index = 0;
  36. while (arraySorted.Count < 100)
  37. {
  38. for (int i = 0; i < array.Length; ++i)
  39. {
  40. if (max <= array[i] && array[i] != 100)
  41. {
  42. max = array[i];
  43. index = i;
  44. }
  45. }
  46. array[index] = 100;
  47. arraySorted.Add(max);
  48. max = int.MinValue;
  49. }
  50. string foo = "";
  51. for (int i = 0; i < arraySorted.Count; ++i)
  52. {
  53. foo += arraySorted[i].ToString() + " ";
  54. }
  55. MessageBox.Show(foo);
  56. }
  57. void methodMinMax()
  58. {
  59. for (int i = 0; i < array.Length - 1; ++i)
  60. {
  61. int max = i;
  62. for (int j = i + 1; j < array.Length; ++j)
  63. {
  64. if (array[j].CompareTo(array[max]) > 0)
  65. {
  66. max = j;
  67. }
  68. }
  69. int temp = array[i];
  70. array[i] = array[max];
  71. array[max] = temp;
  72. }
  73. string foo = "";
  74. for (int i = 0; i < array.Length; ++i)
  75. {
  76. foo += array[i] + " ";
  77. }
  78. MessageBox.Show(foo);
  79. }
  80. void BubbleSort()
  81. {
  82. int temp = 0;
  83. for (int i = 0; i < array.Length - 1; i++)
  84. {
  85. for (int j = 0; j < array.Length - i - 1; j++)
  86. {
  87. if (array[j + 1] < array[j])
  88. {
  89. temp = array[j + 1];
  90. array[j + 1] = array[j];
  91. array[j] = temp;
  92. }
  93. }
  94. }
  95. string foo = "";
  96. for (int i = 0; i < array.Length; ++i)
  97. {
  98. foo += array[i] + " ";
  99. }
  100. MessageBox.Show(foo);
  101. }
  102. void ShuttleSort()
  103. {
  104. int temp = 0;
  105. for (int i = 0; i < array.Length - 1; i++)
  106. {
  107. for (int j = 0; j < array.Length - i - 1; j++)
  108. {
  109. if (array[j + 1] < array[j])
  110. {
  111. temp = array[j + 1];
  112. array[j + 1] = array[j];
  113. array[j] = temp;
  114. }
  115. }
  116. }
  117. string foo = "";
  118. for (int i = 0; i < array.Length; ++i)
  119. {
  120. foo += array[i] + " ";
  121. }
  122. MessageBox.Show(foo);
  123. }
  124. }
  125. }