Synchronization of old projects
Part1
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
namespace Lesson
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Print(int[] arr)
|
||||
{
|
||||
for (int i = 0; i < arr.Length; i++)
|
||||
{
|
||||
Console.Write(arr[i] + " ");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] arr = new int[20];
|
||||
Random r = new Random();
|
||||
for (int i = 0; i < arr.Length; i++)
|
||||
{
|
||||
arr[i] = r.Next(0,101);
|
||||
}
|
||||
Print(arr);
|
||||
int temp;
|
||||
bool isSort;
|
||||
for (int i = 0; i < arr.Length; i++)
|
||||
{
|
||||
isSort = false;
|
||||
for (int j = 0; j < arr.Length - 1 - i; j++)
|
||||
{
|
||||
if (arr[j] > arr[j + 1])
|
||||
{
|
||||
isSort = true;
|
||||
temp = arr[j];
|
||||
arr[j] = arr[j + 1];
|
||||
arr[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
if (!isSort) { break; }
|
||||
}
|
||||
Print(arr);
|
||||
for (int i = 0; i < arr.Length; i++)
|
||||
{
|
||||
isSort = false;
|
||||
for (int j = 0; j < arr.Length - 1 - i; j++)
|
||||
{
|
||||
if (arr[j] < arr[j + 1])
|
||||
{
|
||||
isSort = true;
|
||||
temp = arr[j];
|
||||
arr[j] = arr[j + 1];
|
||||
arr[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
if (!isSort) { break; }
|
||||
}
|
||||
Print(arr);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user