-
大小: 500KB文件類型: .zip金幣: 2下載: 0 次發(fā)布日期: 2021-05-29
- 語言: 其他
- 標(biāo)簽: 數(shù)據(jù)結(jié)構(gòu)??課程設(shè)計(jì)??大二必備??
資源簡介
計(jì)算機(jī)專業(yè)大二必備的,非常好用的數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì) ,代碼完美運(yùn)行,實(shí)驗(yàn)報(bào)告也是寫好了的可以直接用

代碼片段和文件信息
#include
#include
#include?
#include?
#include
#include
using?namespace?std;
#define?HashSize?50
#define?MAX?100
#define?LH?1
#define?EH?0
#define?RH?-1
FILE?*fp;
int?data[20];
int?data2[20];
//********************************************************************
int?Binary_Search(int?keyint?lowint?high)//折半查找
{
int?mid;
if(low?==?high)
{
if(data[low]?==?key)
return?low;
else
return?-1;
}
else
{
mid?=?(low?+?high)?/?2;
if(mid?==?low)
mid++;
if(key? return?Binary_Search(key?low?mid?-?1);
else
return?Binary_Search(key?mid?high);
}
}
void?zheban()
{
int?locate;
int?key;
????if((fp=fopen(“D:\\編程的文件\\查找算法性能比較\\折半查找.txt““r“))==NULL)
{
????printf(“cannot?open?file\n“);
}
????for(int?i=0;i<20;i++)
fscanf(fp“%d“&data[i]);
fclose(fp);
????printf(“\n有序序列為:\n“);
for(int?i=0;i<20;i++)
printf(“%d?“data[i]);
????printf(“\n請(qǐng)輸入要查找的數(shù):?“);
????scanf(“%d“?&key);
????if(key?!=?-1)
????{
????????locate?=?Binary_Search(key019);
????????if(locate?!=?-1)
????????{
????????????printf(“\n值%d的位置為:%d\n\n“?key?locate+1);
????????}
????????else
????????{
????????????printf(“沒有找到%d\n“?key);
????????}
????}
????else
????????exit(1);
????cout< }
//************************************************************************
typedef?struct
{
????int?key;???//關(guān)鍵字
????int?data;????//信息域
}Record;??????????????????????????????????//用給定的關(guān)鍵字值與表中其他元素的關(guān)鍵字值比較
typedef?struct
{
????Record?r[MAX+1];
????int?length;
}SqTable;
int?search(SqTable?sint?k)
{
??int?i;
??s.r[0].key=k;
??i=s.length;??????//自幾用的逆序
??while(s.r[i].key!=k)
????????i--;
??return?i;
}
void?sunxu()
{
????SqTable?s;
????int?wzilenxy;
???printf(“請(qǐng)輸入表長:\n“);
????scanf(“%d“&len);
????s.length=len;
????printf(“請(qǐng)輸入表的各個(gè)元素:\n“);
????for(i=1;i<=len;i++)
????{
????????scanf(“%d“&x);
????????s.r[i].key=x;
????}
?????printf(“請(qǐng)輸入要查找的元素:\n“);
????scanf(“%d“&y);
????wz=search(sy);
????if(wz==0)
????{
????????printf(“不存在:\n“);
????}
????else
????????printf(“位置為:%d“wz);
}
//************************************************************************
void?fibonacci(int?*f)//斐波那契數(shù)
{
f[0]?=?1;
f[1]?=?1;
for(int?i?=?2;i?20;++i)
f[i]?=?f[i?-?2]?+?f[i?-?1];
}
int?fibonacci_search(int?*aint?keyint?n)//斐波那契查找
{
int?low?=?0high?=?n?-?1;
int?mid?=?0;
int?k?=?0;
int?F[20];
fibonacci(F);
while(n?>?F[k]?-?1)?//計(jì)算出n在斐波那契中的數(shù)列
++k;
for(int?i?=?n;i? a[i]?=?a[high];
while(low?<=?high)
{
mid?=?low?+?F[k-1]?-?1;??//根據(jù)斐波那契數(shù)列進(jìn)行黃金分割
if(a[mid]?>?key)
{
high?=?mid?-?1;
k?=?k?-?1;
}
else?if(a[mid]? {
low?=?mid?+?1;
k?=?k?-?2;
}
else{
if(mid?<=?high)?//如果為真則找到相應(yīng)的位置
return?mid;
else
return?-1;
}
}
return?-1;
}
int?Fibonacci()
{
if((fp=fopen(“D:\\編程的文件\\查找算法性能比較\\斐波那契.txt““r“))==NULL
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????698368??2018-07-10?15:15??報(bào)告.doc
?????文件??????????65??2014-05-06?19:06??折半查找.txt
?????文件??????????59??2014-10-29?23:28??散列法.txt
?????文件??????????66??2014-05-06?19:06??斐波那契.txt
?????文件???????22030??2018-03-30?08:39??1數(shù)據(jù)結(jié)構(gòu).cpp
評(píng)論
共有 條評(píng)論