Add files via upload

This commit is contained in:
Mateusz779 2021-12-15 19:35:09 +01:00 committed by GitHub
parent 4f57198ce0
commit 51f598afc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 81 additions and 0 deletions

View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31624.102
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bubble_sort_cs", "bubble_sort_cs\bubble_sort_cs.csproj", "{30BAF4ED-EDD2-45A7-A15C-A58780DDC212}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{30BAF4ED-EDD2-45A7-A15C-A58780DDC212}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30BAF4ED-EDD2-45A7-A15C-A58780DDC212}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30BAF4ED-EDD2-45A7-A15C-A58780DDC212}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30BAF4ED-EDD2-45A7-A15C-A58780DDC212}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6C4FE418-8521-44FD-A1B2-81CBAE63A56E}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
namespace bubble_sort_cs
{
class Program
{
static void Main(string[] args)
{
int[] tmp= { 2, 7, 2, 1, 3, 100, 3, 32, 342, 2, 44, 23 };
int[] sorted = sort_func(tmp,tmp.Length,false);
for (int i = 0; i <= sorted.Length-1; i++)
{
Console.WriteLine(sorted[i]);
}
}
static int[] sort_func(int[] sort, int len,bool repeat)
{
len = len - 1;
bool t = true;
int j = 0;
while (t)
{
for (int i = 0; i <= len - 1; i++)
{
if (sort[i] > sort[i + 1])
{
int tmp = sort[i];
sort[i] = sort[i + 1];
sort[i + 1] = tmp;
j = 0;
}
else if (sort[i] == sort[i + 1]&& !repeat)
{
List<int> tmp = new List<int>(sort);
tmp.RemoveAt(i);
sort = tmp.ToArray();
//for (int a = i; a < len - 1; a++)
// sort[a] = sort[a + 1];
len--;
j = 0;
}
else
{
if (j == len)
t = false;
else
j++;
}
}
}
return sort;
}
}
}