随笔分类 -  C#算法

C#希尔排序算法实现
摘要:using System;using System.Collections.Generic;using System.Text;namespace SortAlgorithms{ class ShellSorter { public void Sort(int[] arr) { int inc; for (inc = 1; inc <= arr.Length / 9; inc = 3 * inc + 1) ; for (; inc > 0; inc /= 3) { for (int i = inc + 1; i <= arr.Length; i += inc) { int t 阅读全文
posted @ 2009-04-27 20:44 WQL.NET 阅读(131) 评论(0) 推荐(0)
C#选择排序算法实现
摘要:using System;using System.Collections.Generic;using System.Text;namespace SortAlgorithms{public class SelectionSorter { private int min; public void Sort(int[] arr) { for (int i = 0; i < arr.Length-1 ; i++) { min = i; for (int j = i + 1; j < arr.Length; j++) { if (j - 1 > 0) { if (arr[j - 1 阅读全文
posted @ 2009-04-27 20:43 WQL.NET 阅读(162) 评论(0) 推荐(0)
C#快速排序算法实现
摘要:using System;using System.Collections.Generic;using System.Text;namespace SortAlgorithms{ class QuicktionSorter { private void Swap(ref int i, ref int r) { int temp; temp = r; r = i; i = temp; } public void Sort(int[] list, int low, int high) { int pivot; int i, r; int mid; if (high <= low) { ret 阅读全文
posted @ 2009-04-27 20:42 WQL.NET 阅读(175) 评论(0) 推荐(0)
C#插入排序算法实现
摘要:using System;using System.Collections.Generic;using System.Text;namespace SortAlgorithms{ class InsertionSorter { public void Sort(int[] arr) { for (int i = 1; i < arr.Length; i++) { int t = arr[i]; int j = i; while ((j > 0) && (arr[j - 1] > t)) { arr[j] = arr[j - 1]; --j; } arr[j] 阅读全文
posted @ 2009-04-27 20:41 WQL.NET 阅读(97) 评论(0) 推荐(0)
C#冒泡算法实现
摘要:using System;using System.Collections.Generic;using System.Text;namespace SortAlgorithms{ class EbullitionSorter { public enum Derection {litter,big }; public void Sort(int[] arr) { int i, j, temp; bool done = false; j = 1; while ((j < arr.Length) && !(done)) { done = true; for (i = 0; i 阅读全文
posted @ 2009-04-27 20:36 WQL.NET 阅读(161) 评论(0) 推荐(0)