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;
- using System.Threading.Tasks;
- namespace Sort
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- // Swap(ref array[0],ref array[1]);
- InsertionSort(array);
- Console.WriteLine(string.Join(" ", array));
- }
- static void InsertionSort(int [] array)
- {
- for (int firstIndex = 1; firstIndex < array.Length; firstIndex++)
- {
- for (int secondIndex = firstIndex; secondIndex > 0; secondIndex--)
- {
- if (array[secondIndex - 1] > array[secondIndex])
- {
- Swap(ref array[secondIndex - 1], ref array[secondIndex]);
- }
- else
- {
- break;
- }
- }
- }
- }
- static void BubbleSort(int[] array)
- {
- while (true)
- {
- bool swap = false;
- for (int index = 0; index < array.Length - 1; index++)
- {
- //to switch to Descending
- if (array[index] > array[index + 1])
- {
- Swap(ref array[index], ref array[index + 1]);
- swap = true;
- }
- }
- if (!swap)
- {
- break;
- }
- }
- return;
- }
- static void Swap(ref int index1, ref int index2)
- {
- int temp = index1;
- index1 = index2;
- index2 = temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment