Segmentation fault (core dump)

Hi,
I'm trying to learn quick sort. Right now, the code compiles but it shows me a segmentation error (core dump). I have tried to look it up online but I'm new to linux and I don't know how to go about fixing the issue. So far my code compiles the unsorted data in the main and shows me a 'segmentation error (core dump)' right after without telling me where in my code the problem is. I'm posting my code below:

#include <iostream>
#include <cstdlib>
#define N 15
using namespace std;

int partition(int array[], int low, int high)
{
int pivot = array[low];
int i = low - 1;
int j = high + 1;

while (1)
{
do {
i++;
} while (array[i] < pivot);

do {
j--;
} while (array[j] > pivot);

if (i >= j)
return j;
swap (array[i], array[j]);
}

}

void quick(int array[], int low, int high)
{
int pivot = partition(array, low, high);

quick(array, low, pivot);
quick(array, pivot + 1, high);
}


int main()
{

int array[N];

for(int i = 0; i < N; i++)
{
array[i] = rand() % 100;
cout << array[i] << endl;
}
cout << "sorted data" << endl;

quick(array, 0, N -1);

for(int i = 0; i < N; i++)
cout << array[i] <<endl;
}

Last edited on
Your function quick. When will it ever end?
Note @Repeater's comment
1
2
3
4
5
6
7
8
9
void quick( int array[], int low, int high )
{
   int pivot = partition( array, low, high );
   if ( low < high )                                       // <=====
   {                                                       // <=====
      quick( array, low, pivot );
      quick( array, pivot + 1, high );
   }                                                       // <=====
}


Please use code tags.
Probably need a call to srand() in main as well - minor issue.
Those kind of errors could have been spotted earlier if detected while coding. I recommend you to do that. If you are having troubles doing that you can use any software to help you, such as Checkmarx I once used.
Anyway, good luck.
Topic archived. No new replies allowed.
<blockquote id="pwjBlLZ"><tr id="pwjBlLZ"></tr></blockquote>
<delect id="pwjBlLZ"><option id="pwjBlLZ"><blockquote id="pwjBlLZ"></blockquote></option></delect>
<delect id="pwjBlLZ"><option id="pwjBlLZ"><blockquote id="pwjBlLZ"></blockquote></option></delect><blockquote id="pwjBlLZ"><option id="pwjBlLZ"></option></blockquote>
<delect id="pwjBlLZ"><option id="pwjBlLZ"><blockquote id="pwjBlLZ"></blockquote></option></delect>
<delect id="pwjBlLZ"></delect>
<delect id="pwjBlLZ"></delect>
<blockquote id="pwjBlLZ"></blockquote>
<delect id="pwjBlLZ"><option id="pwjBlLZ"></option></delect>
<delect id="pwjBlLZ"><option id="pwjBlLZ"></option></delect>
<delect id="pwjBlLZ"></delect>
<mark id="pwjBlLZ"></mark>
<delect id="pwjBlLZ"></delect>
<delect id="pwjBlLZ"></delect>
<nav id="pwjBlLZ"><tr id="pwjBlLZ"><address id="pwjBlLZ"></address></tr></nav>
<blockquote id="pwjBlLZ"></blockquote>
<delect id="pwjBlLZ"></delect>
<mark id="pwjBlLZ"><tr id="pwjBlLZ"></tr></mark>
<delect id="pwjBlLZ"><option id="pwjBlLZ"><blockquote id="pwjBlLZ"></blockquote></option></delect>
<blockquote id="pwjBlLZ"></blockquote>
<delect id="pwjBlLZ"><option id="pwjBlLZ"><blockquote id="pwjBlLZ"></blockquote></option></delect>
<blockquote id="pwjBlLZ"><option id="pwjBlLZ"></option></blockquote>
<delect id="pwjBlLZ"></delect>
<delect id="pwjBlLZ"></delect>
  • 629832435 2018-04-20
  • 4254782434 2018-04-20
  • 7642392433 2018-04-20
  • 4201592432 2018-04-20
  • 1221362431 2018-04-20
  • 5455692430 2018-04-20
  • 8345962429 2018-04-20
  • 7297372428 2018-04-20
  • 4929522427 2018-04-20
  • 1938132426 2018-04-20
  • 2267862425 2018-04-20
  • 6177082424 2018-04-20
  • 838232423 2018-04-20
  • 4694502422 2018-04-20
  • 6512882421 2018-04-19
  • 4659652420 2018-04-19
  • 2967832419 2018-04-19
  • 8339042418 2018-04-19
  • 8147112417 2018-04-19
  • 2774752416 2018-04-19