c#實現所有經典排序演算法
1、選擇排序
選擇排序
class selectionsorter
int t = arr[min];
arr[min] = arr[i];
arr[i] = t;
}
}
static void main(string args)
;
selectionsorter s = new selectionsorter();
s.sort(array);
foreach (int m in array)
console.writeline("", m);
}
} 2、氣泡排序
氣泡排序
class ebullitionsorter
}
j++;
}
}
static void main(string args)
;
ebullitionsorter e = new ebullitionsorter ();
e.sort(array);
foreach (int m in array)
console.writeline("", m);
}
} 3、快速排序
快速排序
class quicksorter
public void sort(int list, int low, int high)
mid = (low + high) >> 1;
pivot = list[mid];
swap(ref list[low], ref list[mid]);
l = low + 1;
r = high;
do
while (l < r);
list[low] = list[r];
list[r] = pivot;
if (low + 1 < r)
sort(list, low, r - 1);
if (r + 1 < high)
sort(list, r + 1, high);
}
static void main(string args)
;
quicksorter q = new quicksorter();
q.sort(iarrary, 0, 13);
for (int m = 0; m <= 13; m++)
console.writeline("", iarrary[m]);
}
}
4、插入排序
插入排序
public class insertionsorter
arr[j] = t;
}
}
static void main(string args)
;
insertionsorter i = new insertionsorter();
i.sort(array);
foreach (int m in array)
console.writeline("", m);
}
}
5、希爾排序
希爾排序
public class shellsorter
arr[j - 1] = t;
}
}
}
static void main(string args)
;
shellsorter s = new shellsorter();
s.sort(array);
foreach (int m in array)
console.writeline("", m);
}
}
C 實現所有經典排序演算法
c 實現所有經典排序演算法 1 選擇排序 希爾排序 public class shellsorter arr j 1 t static void main string args shellsorter s new shellsorter s.sort array foreach int m in ...
C 實現所有經典排序演算法
選擇排序 class selectionsorter int t arr min arr min arr i arr i t static void main string args selectionsorter s new selectionsorter s.sort array foreach...
C 實現所有經典排序演算法
選擇排序 class selectionsorter int t arr min arr min arr i arr i t static void main string args selectionsorter s new selectionsorter s.sort array foreach...