qingcheng奕  
上一页 1 ··· 19 20 21 22 23

2011年4月24日

摘要: #include<iostream>using namespace std;int BinarySearch(int a[],int n,int goal){for(int i=0;i<=n;i++)cout<<a[i]<<endl;int mid,low=0,high=n;while(low<=high){mid=(low+high)/2;if(goal==a[mid])return mid;else if(goal<a[mid])high=mid-1;elselow=mid+1;}return -1;}int main(){int ar 阅读全文
posted @ 2011-04-24 17:27 qingcheng奕 阅读(179) 评论(0) 推荐(0) 编辑
 
摘要: #include<iostream>//#include<algorithm>#include<string.h>using namespace std;struct dict{char en[11];char a[11];}d[100001];int cmp(const void *x,const void *y){return (strcmp((char*)((dict *)x)->a,(char *)((dict*)y)->a ) );}int sBinarySearch(char *s,int low,int high){int mid, 阅读全文
posted @ 2011-04-24 17:26 qingcheng奕 阅读(187) 评论(0) 推荐(0) 编辑
 
摘要: //归并排序 从小到大排序#include<iostream>using namespace std;int arr[10]={10,88,3,7,6,38,87,90,1,19};void Merge(int l,int m,int h);void MergeSort(int low,int high){ int mid; if(low<high) { mid=(low+high)/2; MergeSort(low,mid); MergeSort(mid+1,high); Merge(low,mid,high); } return;}void Merge(int low,i 阅读全文
posted @ 2011-04-24 17:25 qingcheng奕 阅读(171) 评论(0) 推荐(0) 编辑

2011年4月23日

摘要: //插入排序 注意数组的传递方式#include <iostream>using namespace std;void INSERTIONSORT(int ar[],int n) //从小到大排序{ int temp,i,j; for(j=1;j<n;j++) //从0到j-1都是排好的了,现在开始排ar[j] { temp=ar[j]; i=j-1; while(ar[i]>temp &&i>=0) { ar[i+1]=ar[i]; i--; } i++; ar[i]=temp; } return ;}int main(){ int arr[10 阅读全文
posted @ 2011-04-23 22:23 qingcheng奕 阅读(175) 评论(0) 推荐(0) 编辑

2011年4月22日

摘要: //我的第一个递归程序//分治思想,用递归实现//递归,求的一个数组中的最大和最小元素 递归的结构就是 在函数里面 刚开始是结束条件 然后写如果不满足条件的话 怎样递推//有多个返回值的时候,把要返回的作为参数 写到 函数名字中#include<iostream>using namespace std;int arr[9]={22,13,-5,-8,15,60,17,31,47};void MAXMIN(int low,int high,int& fmax,int& fmin) //注意 这里是引用 地址传递{if(low == high){fmax=arr[low 阅读全文
posted @ 2011-04-22 11:05 qingcheng奕 阅读(855) 评论(0) 推荐(0) 编辑
上一页 1 ··· 19 20 21 22 23