Subj : Re: stack overflow before it attempts to sort 1 & 2 million int arrays To : comp.lang.c++,comp.programming From : alfps Date : Sat Aug 13 2005 02:00 am * strotee@gmail.com attempts to implement QuickSort: > > void swap(int *a,int *b) > { > int t=*a; *a=*b; *b=t; > } > void sort(int arr[], int beg, int end) > { > if (end > beg + 1) > { > int piv = arr[beg], l = beg + 1, r = end; > while (l < r) > { > if (arr[l] <= piv) > l++; > else > swap(&arr[l], &arr[--r]); > } > swap(&arr[--l], &arr[beg]); > sort(arr, beg, l); > sort(arr, r, end); > } > } This is not really a C++ question, except the reason why you get a crash. The reason it crashes is you do a million or so recursive calls, or possibly an infinite number (I'm not in the mood for analyzing the details), and on current personal computers a million is about how much stack space you have. The reason you do a million or so recursive calls, or possibly an infinite number, has nothing to do with C++, and figuring this out is presumably part of your assignment (which we won't do for you!), so therefore crossposted to [comp.programming] with follow-ups there. XFUT: [comp.programming] -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? .