学习型 ASP/PHP/ASP.NET 主机 30元/年全能 ASP/PHP/ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
 16 12
发新话题
打印

C语言算法(大家跟贴啊!)

C语言算法(大家跟贴啊!)

大家有什么好的或新颖的或常用的 C语言写的算法,都可以贴出来~~~,供大家学习参考~~

多多益善~~

TOP

################
我的爱好:C和数据库!正在学VC++ 我的QQ:345895839,有共同爱好的加我!期待着与你共同进步!

TOP

################
蒹葭苍苍,白露为霜。所谓伊人,在水一方。溯洄从之,道阻且长。溯游从之,宛在中央。

TOP

是自己的原创吗?

TOP

c++,小妹妹是你自己写的吗
我的主页 http://www.peiren.com

TOP

//************************* //三分检索 //*************************

#include<iostream.h> #include<iomanip.h>

//************************************* //检索给定的值x在有序数组A中出现的位置 //如果有,返回出现的位置,否则返回-1 //*************************************

int ThirdSearch(int A[],int x,int n) { int low,high,mid1,mid2; low=0; high=n; while(low<=high) { mid1=int(low+(high-low)/3); mid2=int(low+((high-low)/3)*2); if(x<A[mid1]) high=mid1-1; else if(x>A[mid1] && x<A[mid2]) {low=mid1+1;high=mid2-1;} else if(x>A[mid2]) low=mid2+1; else if(x==A[mid1]) return mid1; else if(x==A[mid2]) return mid2; } return -1; }

void main(void) { int n,x,i,*pa,result; cout<<"Please Input The Number of Array: "; cin>>n; pa=new int [n]; cout<<"Please Input The Data of Array:"<<endl; for(i=0;i<n;i++) cin>>pa[i]; cout<<"Please Input The Number of Search Number:"; cin>>x; cout<<endl<<"**************************************"<<endl; cout<<"This Array have "<<n<<" Nubmers."<<endl; for(i=0;i<n;i++) cout<<setw(8)<<pa[i]; cout<<endl<<"The Search Number is: "<<x<<endl; cout<<"****************************************"<<endl; cout<<endl<<"The Result of Search is:"<<endl; result=ThirdSearch(pa,x,n); if(result==-1) cout<<"There have not Number in This Array!"<<endl; else cout<<x<<" Location is "<<result<<endl; cout<<"The Program is end"<<endl; }

我的爱好:C和数据库!正在学VC++ 我的QQ:345895839,有共同爱好的加我!期待着与你共同进步!

TOP

是,

这是一个很小的程序,若是有误,请版主指出,我会多多学习与进步!

蒹葭苍苍,白露为霜。所谓伊人,在水一方。溯洄从之,道阻且长。溯游从之,宛在中央。

TOP

不好意思问一下,Rectangle是什么类型,是你定义的吗?

还是在哪个头文件里定义的

我的主页 http://www.peiren.com

TOP

jiely专偷别人的程序!!!大家小心!!!

TOP

以下是引用Kill_jiely在2004-06-02 21:40:54的发言:

jiely专偷别人的程序!!!大家小心!!!

虾米!!!

就偶们写的ABCD也有人偷???

骗人也要好一点的理由

偶支持楼主

偶是一只想要飞却忘了咋飞的菜鸟

TOP

 16 12
发新话题