-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\SortTheOdd\SortTheOdd.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Xunit; | ||
|
||
namespace SortTheOdd.Tests | ||
{ | ||
public class SortTheOddTests | ||
{ | ||
[Fact] | ||
public void Test_Sort1() | ||
{ | ||
Assert.Equal(new int[] { 1, 3, 2, 8, 5, 4 }, SortTheOdd.Sort(new int[] { 5, 3, 2, 8, 1, 4 })); | ||
Assert.Equal(new int[] { 1, 3, 5, 8, 0 }, SortTheOdd.Sort(new int[] { 5, 3, 1, 8, 0 })); | ||
Assert.Equal(new int[] { }, SortTheOdd.Sort(new int[] { })); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31912.275 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SortTheOdd", "SortTheOdd\SortTheOdd.csproj", "{5431BAA1-1C2C-4333-8BD3-D41E96C23E93}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SortTheOdd.Tests", "SortTheOdd.Tests\SortTheOdd.Tests.csproj", "{9073AF51-5E90-40E4-8811-8EFE091919AE}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{5431BAA1-1C2C-4333-8BD3-D41E96C23E93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5431BAA1-1C2C-4333-8BD3-D41E96C23E93}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5431BAA1-1C2C-4333-8BD3-D41E96C23E93}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5431BAA1-1C2C-4333-8BD3-D41E96C23E93}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{9073AF51-5E90-40E4-8811-8EFE091919AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{9073AF51-5E90-40E4-8811-8EFE091919AE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{9073AF51-5E90-40E4-8811-8EFE091919AE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{9073AF51-5E90-40E4-8811-8EFE091919AE}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {B7496AFD-5BDE-4968-A422-6294804995F5} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace SortTheOdd | ||
{ | ||
/// <summary> | ||
/// You will be given an array of numbers. | ||
/// You have to sort the odd numbers in ascending order while leaving the even numbers at their original positions. | ||
/// </summary> | ||
public class SortTheOdd | ||
{ | ||
public static int[] Sort(int[] arr) | ||
{ | ||
if (arr.Length == 0) { return arr; } | ||
var odds = new List<int>(); | ||
var index = new List<int>(); | ||
for (int i = 0; i < arr.Length; i++) | ||
{ | ||
if (arr[i] % 2 != 0) | ||
{ | ||
odds.Add(arr[i]); | ||
index.Add(i); | ||
} | ||
} | ||
|
||
var oddsArr = odds.ToArray(); | ||
Array.Sort(oddsArr); | ||
|
||
for (int i = 0; i < index.Count; i++) | ||
{ | ||
arr[index[i]] = oddsArr[i]; | ||
} | ||
return arr; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |