Advertisement
illiden

SortFunction

Jul 8th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Lesson1
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] array = { 56, 43, 2, 77, 234, 56, 34, 99 };
  11.             int[] sortedArray = Sort(array);
  12.  
  13.             foreach (int number in array)
  14.             {
  15.                 Console.Write(number + " ");
  16.             }
  17.             Console.WriteLine();
  18.             foreach (int number in sortedArray)
  19.             {
  20.                 Console.Write(number + " ");
  21.             }
  22.  
  23.             Console.ReadKey();
  24.         }
  25.  
  26.         static int[] Sort(int[] array)
  27.         {
  28.             int[] sortedArray = new int[array.Length];
  29.             for (int i = 0; i < array.Length; i++)
  30.             {
  31.                 sortedArray[i] = array[i];
  32.             }
  33.             for (int i = 0; i < sortedArray.Length; i++)
  34.             {
  35.                 for (int j = 0; j < sortedArray.Length - 1; j++)
  36.                 {
  37.                     if(sortedArray[j] < sortedArray[j + 1])
  38.                     {
  39.                         int bufer = sortedArray[j];
  40.                         sortedArray[j] = sortedArray[j + 1];
  41.                         sortedArray[j + 1] = bufer;
  42.                     }
  43.                 }
  44.             }
  45.             return sortedArray;
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement