以文本方式查看主题 - 计算机科学论坛 (http://bbs.xml.org.cn/index.asp) -- 『 编程心得 』 (http://bbs.xml.org.cn/list.asp?boardid=42) ---- 刚写的一段快速排序算法,尽可能的面向对象,请大家在质量属性各个方面给出批评意见。 (http://bbs.xml.org.cn/dispbbs.asp?boardid=42&rootid=&id=26470) |
-- 作者:pennyliang -- 发布时间:1/16/2006 12:58:00 AM -- 刚写的一段快速排序算法,尽可能的面向对象,请大家在质量属性各个方面给出批评意见。 //主要考虑的因素,可读性,分解均衡性。如果大家对快速排序遗忘,在看了这段代码很 //容易回忆出来,目的就达到了 #include <cstdlib> using namespace std; QuickSort::QuickSort(int* unSortedArray,int low,int high) bool QuickSort::Process() QuickSort *quickSortRight = new QuickSort(m_array,splitPoint+1,m_last); return true; int QuickSort::Partition(int key,int low,int high) while(low<high) return low; int QuickSort::ExtendLargeRegion(int key,int lowVac,int high) return highVac; int QuickSort::ExtendSmallRegion(int key,int low,int highVac) return lowVac;
[此贴子已经被作者于2006-1-16 10:44:26编辑过]
|
-- 作者:pennyliang -- 发布时间:1/16/2006 1:00:00 AM -- 这居然是本学期写的第二次代码。 |
-- 作者:pennyliang -- 发布时间:1/16/2006 12:45:00 PM -- //根据好友Loki的意见修改的代码 #include <cstdlib> using namespace std; QuickSort::QuickSort(int* unSortedArray,int low,int high) int QuickSort::Partition(int key,int low,int high) while(low<high) return low; int QuickSort::ExtendLargeRegion(int key,int lowVac,int high) return highVac; int QuickSort::ExtendSmallRegion(int key,int low,int highVac) return lowVac; bool QuickSort::QuickSortRegion(int low,int high) bool QuickSort::QuickSortLeftRegion(int low,int high) bool QuickSort::QuickSortRightRegion(int low,int high)
[此贴子已经被作者于2006-1-16 13:16:42编辑过]
|
-- 作者:pennyliang -- 发布时间:1/16/2006 6:19:00 PM -- //根据chen3feng的意见修改第三个版本 #include <cstdlib> #include <iostream> using namespace std; class QuickSort private: public : private: QuickSort::QuickSort(int* unSortedArray, int low, int high) QuickSort::~QuickSort() bool QuickSort::Process() if (m_first < m_last) return true; int QuickSort::Partition(int key, int low, int high) while (low < high) return low; int QuickSort::ExtendLargeRegion(int key, int lowVac, int high) for (curr = high;curr > lowVac;curr--) return highVac; int QuickSort::ExtendSmallRegion(int key, int low, int highVac) for (curr = low;curr < highVac;curr++) return lowVac; bool QuickSort::QuickSortRegion(int low, int high) bool QuickSort::QuickSortLeftRegion(int low, int high) bool QuickSort::QuickSortRightRegion(int low, int high) int main(int argc, char *argv[]) |
-- 作者:pennyliang -- 发布时间:1/16/2006 6:25:00 PM -- //这个是我两年前写得代码 #include "stdafx.h" int list[] = void exchange(int&a, int&b) int partition(int list[], int l, int h, int pivotal) exchange(list[pivotal], list[l]); int pivotpos = l; pivotval = list[pivotpos]; for (int i = l + 1;i <= h;i++) if (list[i] < pivotval && ++pivotpos != i) exchange(list[l], list[pivotpos]); }; int quicksort(int list[], int l, int h) if (h > l) pivotal = (l + h) / 2; int pivotpos = partition(list, l, h, pivotal); quicksort(list, l, pivotpos - 1); return 0; int main(int argc, char* argv[]) |
-- 作者:reallyh -- 发布时间:2/12/2006 6:45:00 PM -- 还真给忘了呵呵 3ks |
-- 作者:pennyliang -- 发布时间:3/13/2006 3:46:00 PM -- using System; using System.Collections; using NUnit.Framework; namespace Algorithm.Sort #region Ctor #region ISort 成员 public bool Sort() #endregion #region Private Fun while (low < high) return low; for (curr = high;curr > lowVac;curr--) return highVac; for (curr = low;curr < highVac;curr++) #region IComparable 成员 public int CompareTo(object obj) #endregion ArrayList people2 = new ArrayList(); foreach (TestObjcet p in people1) |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
125.000ms |