Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Фамилия имя #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions CourseApp/Module2/BubbleSort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,39 @@ namespace CourseApp.Module2
{
public class BubbleSort
{
public static void BubbleSortMethod()
public static void BubbleSortMeth()
{
int n = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
string[] sValues = s.Split(' ');
int[] arr = new int[n];
for (int i = 0; i < n; i++)
{
arr[i] = int.Parse(sValues[i]);
}
int arr_size = int.Parse(Console.ReadLine());
string[] arr_str = Console.ReadLine().Split(' ');
int[] arr = new int[arr_size];

for (int i = 0; i < arr.Length - 1; i++)
{
for (int j = 0; j < arr.Length - i - 1; j++)
//Строковый массив в целочисенный массив
for(int i = 0; i < arr_size; ++i)
{
if (arr[j] > arr[j + 1])
arr[i] = int.Parse(arr_str[i]);
}

//Были перестановки или нет
bool flag = false;
//Сортировка
for(int i = 0; i < arr_size; ++i)
{
for(int j = 0; j < arr_size - i - 1; ++j)
{
// int temp = arr[j];
// arr[j] = arr[j + 1];
// arr[j+1] = temp;
(arr[j], arr[j + 1]) = (arr[j + 1], arr[j]);
if(arr[j] > arr[j+1])
{
(arr[j], arr[j+1]) = (arr[j+1], arr[j]);
string reslt = string.Join(" ", arr);
Console.WriteLine(reslt);
flag = true;
}
}
}
}

string result = string.Join(" ", arr);
Console.WriteLine(result);

if(flag == false)
{
Console.WriteLine("0");
}
}
}
}
}
33 changes: 33 additions & 0 deletions CourseApp/Module2/MergeSort.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

namespace CourseApp.Module2
{
public class MergeSort
{
public static int[] Merge(int[] a, int[] b)
{
int indxA = 0;
int indxB = 0;
int k = 0;
int[] result = new int[a.Length + b.Length];
int n = a.Length + b.Length;

while(k < result.Length)
{
if(indxB == b.Length || (indxA < a.Length && a[indxA] < b[indxB]))
{
result[k] = a[indxA];
indxA++;
}
else
{
result[k] = b[indxA];
indxB++;
}
k++;
}

return result;
}
}

}
57 changes: 57 additions & 0 deletions CourseApp/Module2/PairBublSort.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;

namespace CourseApp.Module2
{
public class PairBublSort
{
public static void PairBubbleSort()
{

int n = Convert.ToInt32(Console.ReadLine());
string[] arr_str;
int[,] arr = new int[n, 2];

for(int i = 0; i < n; ++i)
{
//Получение строк
string str = Console.ReadLine();
arr_str = str.Split(' ');

//Преобразование строк в числа
arr[i, 0] = int.Parse(arr_str[0]);
arr[i, 1] = int.Parse(arr_str[1]);
}

for(int i = 0; i < n - 1; ++i)
{
for(int j = 0; j < n - 1; ++j)
{
//Сортировка по цене
if(arr[j, 1] < arr[j + 1, 1])
{
(arr[j + 1, 1], arr[j, 1]) = (arr[j, 1], arr[j + 1, 1]);
(arr[j + 1, 0], arr[j, 0]) = (arr[j, 0], arr[j + 1, 0]);
}
//Сортируем по идентификационному номеру, когда цена одинакова
else if(arr[j, 1] == arr[j + 1, 1])
{
if(arr[j, 0] > arr[j + 1, 0])
{
(arr[j + 1, 0], arr[j, 0]) = (arr[j, 0], arr[j + 1, 0]);
}
}
}
}
Console.WriteLine();
for(int i = 0; i < n; ++i)
{
for(int j = 0; j < 2; ++j)
{
Console.Write(arr[i, j]);
Console.Write(" ");
}
Console.WriteLine();
}
}
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Tprogramming_42_2020
# Tprogramming_147_2022

Master branch :)
Shokhin Akim 1/147

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

крутой