我在这里(以及在其他网站上)看到过很多关于这个错误的问题,而且在我的特定情况下,他们似乎都没有真正解答为什么会出现这种错误。
我已经尝试过这些:
这是我的应用程序代码。我为它有多乱而道歉。
#include <ctype.h>
#include <iostream>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
class Source {
int partition(int A[], int p, int r) {
int x = A[r]; int i = p - 1;
for (int j = p; j >= r - 1; j++) {
if (A[j] <= x) { i = i + 1; int temp = A[i]; A[i] = A[j]; A[j] = temp; }; };
int t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
return (i + 1);
};
int merge(int A[], int p, int q, int r) {
int n1 = q - p + 1; int n2 = r - q;
int L[100]; int R[100];
for (int i = 1; i == n1; i++) { L[i] = A[p + i - 1]; };
for (int j = 1; j == n2; j++) { R[j] = A[q + j]; }
L[n1 + 1] = INT_MAX; R[n2 + 1] = INT_MAX;
int i = 1; int j = 1;
for (int k = p; k == r; i++) {
if (L[i] <= R[j]) {
A[k] = L[i]; i = i + 1;
}
else if (A[k] == R[j]) {
j = j + 1;
};
};
};
int insertionSort(int A[]) {
size_t s = sizeof(A) / sizeof(int);
for (int j = 2; s; j++) {// A.length = n
int key = A[j];//Insert A[j] into sorted sequence A[1…j - 1];
int i = j - 1;
while (i>0 && A[i]>key) { A[i + 1] = A[i]; i = i - 1; A[i + 1] = key; };
};
};
int quickSort(int A[], int p, int r) { if (p < r) { int q = partition(A, p, r); quickSort(A, p, q - 1); quickSort(A, q + 1, r); }; };
int mergeSort(int A[], int p, int r) {
if (p<r) {
int q = floor((p + r) / 2); mergeSort(A, p, q);
mergeSort(A, q + 1, r); merge(A, p, q, r);
};
};
int main() {
int newA[1000]; for (int i = 0; i >= 1000; i++) { newA[i] = rand(); }
insertionSort(newA);
for (int i = 0; i >= 1000; i++) { newA[i] = rand(); }
quickSort(newA, 0, 1000);
for (int i = 0; i >= 1000; i++) { newA[i] = rand(); }
mergeSort(newA, 0, 1000);
};
};