From 51f598afc345d55aa6cbbcc95f184763c411482c Mon Sep 17 00:00:00 2001 From: Mateusz779 <73058906+Mateusz779@users.noreply.github.com> Date: Wed, 15 Dec 2021 19:35:09 +0100 Subject: [PATCH] Add files via upload --- bubble_sort_cs/bubble_sort_cs.sln | 25 +++++++++++ bubble_sort_cs/bubble_sort_cs/Program.cs | 56 ++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 bubble_sort_cs/bubble_sort_cs.sln create mode 100644 bubble_sort_cs/bubble_sort_cs/Program.cs diff --git a/bubble_sort_cs/bubble_sort_cs.sln b/bubble_sort_cs/bubble_sort_cs.sln new file mode 100644 index 0000000..1d6c26c --- /dev/null +++ b/bubble_sort_cs/bubble_sort_cs.sln @@ -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 diff --git a/bubble_sort_cs/bubble_sort_cs/Program.cs b/bubble_sort_cs/bubble_sort_cs/Program.cs new file mode 100644 index 0000000..32fc4af --- /dev/null +++ b/bubble_sort_cs/bubble_sort_cs/Program.cs @@ -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 tmp = new List(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; + } + } +}