| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2094 人关注过本帖
标题:C语言算法(大家跟贴啊!)
取消只看楼主 加入收藏
jiely
Rank: 1
等 级:新手上路
帖 子:106
专家分:0
注 册:2004-5-15
收藏
 问题点数:0 回复次数:2 
C语言算法(大家跟贴啊!)

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

多多益善~~

搜索更多相关主题的帖子: C语言 跟贴 算法 
2004-05-31 23:37
jiely
Rank: 1
等 级:新手上路
帖 子:106
专家分:0
注 册:2004-5-15
收藏
得分:0 
################

我的爱好:C和数据库!正在学VC++ 我的QQ:345895839,有共同爱好的加我!期待着与你共同进步!
2004-05-31 23:48
jiely
Rank: 1
等 级:新手上路
帖 子:106
专家分:0
注 册:2004-5-15
收藏
得分:0 

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

#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,有共同爱好的加我!期待着与你共同进步!
2004-06-01 23:59
快速回复:C语言算法(大家跟贴啊!)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016644 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved