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

#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;
}

查看全部
weixin_51754509
月巴氵告
2020/12/05 19:15
  • c语言
  • 点赞
  • 收藏
  • 回答
    私信

6个回复