-
Notifications
You must be signed in to change notification settings - Fork 0
/
BubbleSortMethodFunction2.cs
63 lines (62 loc) · 1.71 KB
/
BubbleSortMethodFunction2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace BubbleSortMethodFunction
{
class Program
{
static void Main(string[] args)
{
Random rd = new Random();
SetBufferSize(WindowWidth, WindowHeight);
do
{
int[] a = new int[rd.Next(7, 17)];
FillArray(a, rd);
DisplayArray(a);
string[] s = { "Hakob", "Asgo", "Parandzem", "EF", "SG", "AB" };
BubbleSort(s);
WriteLine();
foreach(var s1 in s)
{
WriteLine(s1);
}
WriteLine();
} while (ReadKey().Key == ConsoleKey.Enter);
}
public static void FillArray(int[] a, Random rd)
{
for(int i = 0; i <a.Length; i++)
{
a[i] = rd.Next(-99, 100);
}
}
public static void DisplayArray(int[] array)
{
WriteLine("Funciton Size is " + array.Length);
foreach(int i in array)
{
Write(i + "\t");
}
WriteLine();
}
public static void BubbleSort(string [] s)
{
for (int i = 0; i < s.Length-1; i++)
{
for (int k = 0; k < s.Length - i - 1; k++)
{
if(s[k].CompareTo(s[k+1])>0)
{
string temp = s[k + 1];
s[k+1] = s[k];
s[k] = temp;
}
}
}
}
}
}