The code is here, and it is compiled by G++. After input N=600000 and enter. A window popped out said that *.exe has stopped working. When debugging the code, a window titled Error said that Program received signal SIGSEGV, Segmentation fault. when come to sort line. Now, I know it's stackoverflow error.Thank you, all guys!
#include <iostream>
#include <stdlib.h> /* srand, rand */
#include <algorithm>
int main (int argc, char *argv[]) {
int N;
std::cout << "N:";
int a[N];
for(int i = 0; i < N; i++){
a[i] = rand()%N;
}
std::sort(a,a+N);
std::cout << "The "<<N/2<<"th smallest number is: " << a[N/2-1] <<"
";
return 0;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…