-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
add C# selectsort in SelectionSort #690
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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]) | ||||||||||
{ | ||||||||||
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if 语句这里也稍微改一下 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好的 |
||||||||||
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; | ||||||||||
} | ||||||||||
|
||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.