Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ShakerSort
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { Sort(); //Your code goes here Console.WriteLine("Hello, world!"); } /*Основная программа*/ static void Sort() { int[] myint = { 99, 88, 77, 66, 55, 44, 33, 22, 11, 8, 5, 3, 1 }; WriteArray(myint); ShakerSort(myint); WriteArray(myint); } /* Шейкер-сортировка */ static void ShakerSort(int[] myint) { int left = 0, right = myint.Length - 1, count = 0; while(left <= right) { for (int i = left; i < right; i++) { count++; if (myint[i] > myint[i + 1]) Swap(myint, i, i + 1); } right--; for (int i = right; i > left; i--) { count++; if (myint[i - 1] > myint[i]) Swap(myint, i - 1, i); } left++; } Console.WriteLine("\nКоличество сравнений = {0}", count.ToString()); } /* Поменять элементы местами */ static void Swap(int[] myint, int i, int j) { int glass = myint[i]; myint[i] = myint[j]; myint[j] = glass; } /*Вывести массив*/ static void WriteArray(int[] a) { foreach (int i in a) Console.Write("{0}|", i.ToString()); Console.WriteLine("\n\n\n"); } } }
run
|
edit
|
history
|
help
0
Gamez
c# piramid yapımı
Ship! Wall
1
HashPassword
Lesson 2
look at this, soaches
Hello,rakib!
Stackoverflow 28125983
RegularExpressions