月巴氵告 2020-12-05 19:15 采纳率: 0%
浏览 0

求大神帮助为什么编译运行不了

#include<iostream> #include<stdio.h> #include<stdlib.h>
using namespace std;
 #define N 10//初始空间大小 #define n 10//增加空间大小 template<class Type>
void sort(Type a[],int num)
{
double temp;
for(int i = 1;i <= num-1;i++){
for(int j = 0;j < num-i;j++){
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
}
template<class Type>
int Search(Type *a,Type x,int m){
int left=0;
int right=m-1;
while(left<=right){
int middle = (left+right)/2;
if(x==a[middle])
return middle;
if(x>a[middle])
left=middle+1;
else
right=middle-1;
}
return -1;
}
2

int main(){
int *a,num,length,i = 0;
a = (int *)malloc(sizeof(int)*N); cout<<"请输入一组数(Ctrl+z 停止输入)"<<endl; while(cin>>a[i]){
i++;
if(i>=N){
a = (int *)realloc(a,sizeof(int)*(length+n));
length += n;
}
}
sort(a,i);
for(int j = 0;j <i;j++){
cout<<a[j]<<" ";
}
cout<<endl;
cin.clear();
cout<<"请输入要查找的数: ";
cin>>num;
if(Search(a,num,i)!=-1){
cout<<num<<" 在 数 组 中 , a["<<Search(a,num,i)<<"]="<<num<<endl;
}
else{
cout<<num<<"不在数组中";
}
double *b,num1;
int length1,i1 = 0;
b = (double *)malloc(sizeof(double)*N); cout<<"请输入一组数"<<endl;
while(cin>>b[i1]){
i1++;
if(i1>=N){
b = (double *)realloc(a,sizeof(double)*(length1+n)); length1 += n;
}
}
3

sort(b,i1);
for(int j = 0;j <i1;j++){
cout<<b[j]<<" ";
}
cout<<endl;
cin.clear();
cout<<"请输入要查找的数: ";
cin>>num1;
if(Search(b,num1,i1)!=-1){
cout<<num1<<" 在 数 组 中 , a["<<Search(b,num1,i1)<<"]="<<num1<<endl; }
else{
cout<<num1<<"不在数组中";
}
return 0;
}

  • 写回答

10条回答 默认 最新

  • 鲛人泣珠 2020-12-05 20:39
    关注

    你这是C++

    评论

报告相同问题?

悬赏问题

  • ¥50 关于在matlab上对曲柄摇杆机构上一点的运动学仿真
  • ¥15 jetson nano
  • ¥15 :app:debugCompileClasspath'.
  • ¥15 windows c++内嵌qt出现数据转换问题。
  • ¥20 公众号如何实现点击超链接后自动发送文字
  • ¥15 用php隐藏类名和增加类名
  • ¥15 算法设计与分析课程的提问
  • ¥15 用MATLAB汇总拟合图
  • ¥15 智能除草机器人方案设计
  • ¥15 对接wps协作接口实现消息发送