-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
118 lines (116 loc) · 3.95 KB
/
Program.cs
File metadata and controls
118 lines (116 loc) · 3.95 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Net;
namespace ONELLECT
{
class Program
{
static HttpWebRequest request;
delegate int[] MethodsArray(int[] array);
static int[] Input()
{
int[] array = new int[new Random().Next(20, 101)];
for (int i = 0; i < array.Length; ++i)
{
array[i] = new Random().Next(-100, 101);
}
return array;
}
static void Print(int[] array)
{
using StreamWriter stream = new(request.GetRequestStream());
for (int i = 0; i < array.Length; ++i)
{
Console.Write($"{array[i]} ");
stream.Write($"{array[i]} ");
}
Console.WriteLine();
stream.WriteLine();
}
static int[] BubbleSort(int[] array)
{
for (int i = 0; i < array.Length; i++)
{
for (int j = i + 1; j < array.Length; j++)
{
if (array[i] > array[j])
{
(array[i], array[j]) = (array[j], array[i]);
}
}
}
Console.WriteLine("Выполнена сортировка пузырьком:");
return array;
}
static int[] GnomeSort(int[] array)
{
int i = 1, j = 2;
while (i < array.Length)
{
if (array[i - 1] < array[i])
{
i = j++;
}
else
{
(array[i - 1], array[i]) = (array[i], array[i - 1]);
--i;
if (i == 0)
{
i = j++;
}
}
}
Console.WriteLine("Выполнена гномья сортировка:");
return array;
}
static int[] ShakerSort(int[] array)
{
int left = 0, right = array.Length - 1, count = 0;
while (left < right)
{
for (int i = left; i < right; i++)
{
++count;
if (array[i] > array[i + 1])
{
(array[i], array[i + 1]) = (array[i + 1], array[i]);
}
}
--right;
for (int i = right; i > left; i--)
{
++count;
if (array[i - 1] > array[i])
{
(array[i - 1], array[i]) = (array[i], array[i - 1]);
}
}
++left;
}
Console.WriteLine("Выполнена шейкерная сортировка:");
return array;
}
static void Main()
{
dynamic config = JObject.Parse(new StreamReader("config.json").ReadToEnd());
request = (HttpWebRequest)WebRequest.Create(config.Url.ToString());
request.Method = "POST";
request.Accept = "application/json";
request.ContentType = "text/plain";
MethodsArray[] methods = new MethodsArray[] { BubbleSort, GnomeSort, ShakerSort };
int[] array = Input();
Console.WriteLine("Исходный массив:");
Print(array);
Print(methods[new Random().Next(0, 3)](array));
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader streamReader = new(response.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
Console.WriteLine(result);
}
Console.WriteLine(response.StatusCode);
}
}
}