摘要: 代码中在第一层循环中增加一个bool值,是为了防止在排序完成后还继续无谓的比较,最多会有(n-1)*(n-2)/2次循环。 1 #include 2 using namespace std; 3 void bumbleSort(int a[],int l) 4 { 5 for(int i = 0;ia[j+1])13 {14 if(b)15 b = false;16 int temp = a[j];17 a[j] = a[j+1];18 a[j+1] = temp;19 }20 21 }22 ... 阅读全文
posted @ 2014-02-20 15:09 轻度YYy 阅读(213) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 using namespace std; 3 int partition(int a[],int p,int q){ 4 int x = a[q]; 5 int i = p-1; 6 for(int j = p;j<q;j++) 7 { 8 if(a[j]<x) 9 {10 i++;11 int temp = a[j];12 a[j] = a[i];13 a[i] = temp;14 }15 }16 a[q]=a[i+1];17 a[i+1]=x;18 return i+1;19 }20 void qsort(int a[],int p,int q){21 阅读全文
posted @ 2014-02-20 13:35 轻度YYy 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 其实把程序用到生活中,真的能节约不少时间!程序的力量是无穷滴!哥们的毕业设计是要做法律文书匹配之类的东东,有一步是要抽取所有的法律法规名称,而刚好我们要处理的文件中,法规的名称之前都有个‘.‘,所以用下面的代码处理很方便。以下分别是处理前后的文件格式:只有十几行的代码 1 #include 2 #include 3 #include 4 using namespace std; 5 int main(){ 6 fstream f("1.txt",ios::in|ios::out); 7 fstream ff("3.txt",ios::out); 8 st 阅读全文
posted @ 2014-02-20 11:08 轻度YYy 阅读(266) 评论(0) 推荐(0) 编辑