Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- //task 7: Sorting an array means to arrange its elements in increasing order.
- //Write a program to sort an array. Use the "selection sort" algorithm:
- //Find the smallest element, move it at the first position, find the smallest from the rest, move it at the second position, etc.
- namespace Task7Sort
- {
- class Sort
- {
- static void Main(string[] args)
- {
- int[] array ={ 1, 4, 2, 8, 12, 66, -66, 4, 0, 5, -23, 55, 64, 32, 1, 0, -3 };
- int[] temp = new int[array.Length];
- int min;
- for (int i = 0; i < array.Length ; i++)
- {
- min = i;
- for (int j = i + 1; j < array.Length; j++)
- {
- if (array[j] < array[min])
- {
- min = j;
- }
- }
- if (min != i)
- {
- temp[min] = array[i];
- array[i] = array[min];
- array[min] = temp[min];
- }
- }
- foreach (int element in array)
- {
- Console.Write(element + " ");
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement