forked from doocs/leetcode
-
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.
feat: add c# code in SelectionSort (doocs#691)
- Loading branch information
Showing
2 changed files
with
78 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
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,36 @@ | ||
using static System.Console; | ||
namespace Pro; | ||
public class Program | ||
{ | ||
public static void Main() | ||
{ | ||
int[] test = new int[] {90, 12, 77, 9, 0, 2, 23, 23, 3, 57, 80}; | ||
SelectionSortNums(test); | ||
foreach (var item in test) | ||
{ | ||
WriteLine(item); | ||
} | ||
} | ||
public static void SelectionSortNums(int[] nums) | ||
{ | ||
for (int initial = 0; initial < nums.Length; initial++) | ||
{ | ||
for (int second_sort = initial; second_sort < nums.Length; second_sort++) | ||
{ | ||
if (nums[initial] > nums[second_sort]) | ||
{ | ||
swap(ref nums[initial], ref nums[second_sort]); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
private static void swap(ref int compare_left, ref int compare_right) | ||
{ | ||
int temp = compare_left; | ||
compare_left = compare_right; | ||
compare_right = temp; | ||
} | ||
|
||
} |