归并排序 灵异事件
#include <iostream>using namespace std;
void mergeArry(int a[], int lfirst, int llast, int rfirst, int rlast){
int n = rlast - lfirst + 1;
int *tmp = new int;
int lindex = lfirst, rindex = rfirst;
int i=0;
while(lindex <= llast && rindex <= rlast)
tmp = (a > a? a : a);
while(lindex <= llast)
tmp = a;
while(rindex <= rlast)
tmp = a;
for(int j = 0; j < n; j++){
a = tmp;
}
delete []tmp;
}
void mergeSort(int a[], int first, int last){
if(first < last){
int middle = (last + first) >> 1;
mergeSort(a, first, middle);
mergeSort(a, middle + 1, last);
mergeArry(a, first, middle, middle + 1, last);//将两个数组合并
}
}
int main(){
int a[] = {13,45,87,21,987,23,13,0,5,23,546,78,456,2134,76,34,87,99,65,12};
int len = sizeof(a)/sizeof(a);
cout<<len<<endl;
mergeSort(a, 0, 20);
cout<<len<<endl;
for(int i=0; i< len; i++)
cout<<a<<' ';
cout<<endl;
}
为什么局部变量len会变,而且还插入到了数组a中,
我快被这个问题搞崩溃了{:10_247:}
求助!!!{:10_282:} 这是想干个什么
页:
[1]