Я получаю следующую ошибку из Eclipse IDE, но я не уверен, как решить эту проблему.Кто-нибудь даст мне какой-нибудь совет, пожалуйста?Я новичок в кодировании.
Пробовал разные IDE.Мой код работает в онлайн-среде, но не в других.
using namespace std;
using namespace std::chrono;
void Swap(int *x,int *y) {
int temp=*x;
*x=*y;
*y=temp;
}
void Insertion(int A[],int n) {
int i,j,x;
for(i=1;i<n;i++) {
j=i-1;
x=A[i];
while(j>-1 && A[j]>x){
A[j+1]=A[j];
j--;
}
A[j+1]=x;
}
}
void Merge(int A[],int l,int mid,int h) {
int i=l,j=mid+1,k=l;
int B [500000];
while(i<=mid && j<=h) {
if(A[i]<A[j])
B[k++]=A[i++];
else
B[k++]=A[j++];
}
for(;i<=mid;i++) {
B[k++]=A[i];
}
for(;j<=h;j++) {
B[k++]=A[j];
}
for(i=l;i<=h;i++) {
A[i]=B[i];
}
}
void MergeSort(int A[],int l,int h) {
if(l<h) {
int mid=(l+h)/2;
MergeSort(A,l,mid);
MergeSort(A,mid+1,h);
Merge(A,l,mid,h);
}
}
void ArrayAscend (int A[], int n) {
for (int a = 0; a < n ; a++) {
A [a] = a + 1;
}
}
void ArrayRandom (int A[], int n) {
ArrayAscend (A,n);
srand (time(NULL));
for (int i= n-1 ; i > 0; i--) {
int j = rand () % (i+1);
Swap (&A[i], &A[j]);
}
}
void ArrayDescend (int A[], int n) {
for (int a = 0; a < n ; a++) {
A [a] = n - a;
}
}
int main() {
int arraySize500000 = 500000;
int array500000[arraySize500000] = {};
cout << "*********************Insertion Sort*********************" <<endl;
cout << "---------- Arrays with 500000 Integers ----------" <<endl;
ArrayAscend (array500000,arraySize500000);
auto t1 = system_clock::now();
Insertion(array500000,arraySize500000);
auto t2 = system_clock::now();
auto duration1 = duration_cast<microseconds>(t2-t1);
cout << "Array in ascending order took " << duration1.count()<<" microseconds"<<endl;
ArrayDescend (array500000,arraySize500000);
auto t3 = system_clock::now();
Insertion(array500000,arraySize500000);
auto t4 = system_clock::now();
auto duration2 = duration_cast<microseconds>(t4-t3);
cout << "Array in descending order took " << duration2.count()<<" microseconds"<<endl;
ArrayRandom (array500000,arraySize500000);
auto t5 = system_clock::now();
Insertion(array500000,arraySize500000);
auto t6 = system_clock::now();
auto duration3 = duration_cast<microseconds>(t6-t5);
cout << "Array in random order took " << duration3.count()<<" microseconds"<<endl;
return 0;
}
Я ожидаю вывод длительности каждой вставки сортировки.Тем не менее я получаю следующую ошибку при отладке.
Не удалось выполнить команду MI: -data -valu-expression * ((array500000) +30000) @ 10000 Сообщение об ошибке от серверной части отладчика: Не удается получить доступпамять по адресу 0x42f250