所有栏目 | 云社区 美国云服务器[国内云主机商]
你的位置:首页 > 云社区 » 正文

C++代码,顺序表的遍历,查找,删除,求改正?

发布时间:2020-04-15 16:54:45

资讯分类:顺序表  遍历  改正  删除  查找  调用  函数
C++代码,顺序表的遍历,查找,删除,求改正?

#include<stdio.h>

#include<iostream.h>

//usingnamespacestd;

#defineN8

voidSequence_search(intarray_then[],intnum) //顺序查找

{

cout<<"Sequence_searchn"<<endl;

inti=0;

while(num!=array_then[i++]&&i<N);

if(i>=N)

{

cout<<"Thenumberisnotfoundn"<<endl;

}

else

{

cout<<"Thenumberisfoundn"<<endl;

}

}

voidBinary_chop(intarray_then[],intnum) //二分查找

{

cout<<"Binary_chopn"<<endl;

intflah,low,high;

flah=low=0;

high=N-1;

while(low<=high)

{

flah=(low+high)/2;

if(num>array_then[flah])

{

low=flah+1;

}

elseif(num<array_then[flah])

{

high=flah-1;

}

else

{

cout<<"Thenumisfound:"<<array_then[flah]<<endl;

break;

}

}

}

intmain()

{

intarray[N]={0};

inti=0;

intnum_source=0;

for(i=0;i<N;i++)

cin>>array[i];

cout<<"pleaseinputthenumberyouwanttofind"<<endl;

cin>>num_source;

Sequence_search(array,num_source); //调用顺序查找函数

Binary_chop(array,num_source); //调用二分查找函数

getchar();

return(0);

}

假如还有不懂加我QQ596041016

留言与评论(共有 0 条评论)
   
验证码:
Top