Bug or wrong code?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>;
using namespace std;


int Pivot(int info[],int left,int right){
int temp;
int p=info[left];
int l=left-1;
int r=right+1;


while(l < r){
	if(info[r] < p){
	r--;	
	}

	if(info[l] > p){
	l++;
	}

	//swap feature
	if(l < r){
	temp =	info[l];
	info[l]=info[r];
	info[r] = temp;
	}

	

}
return r;
}
void Quicksort(int info[],int left,int right){
	int middle;
	if (left<right)
	{
		middle = Pivot(info,left,right);
		Quicksort(info,left,middle);
		Quicksort(info,middle+1,right);
	}

}



int main(){
	int Test[10]={5,6,7,9,10,11,8,12,15,16};
	Quicksort(Test,0,10);
	for(int i=0;i<10;i++){
	cout << Test[i]<< "\n";
	}
	system("PAUSE");
	return 0;
}



this is my quicksort function. It worked once but now it isn't outputting anything . Anyone have any idea what is wrong with it.
How and where are you running the code?
visual c++ 2010
can someone check if it works for them
1
2
3
4
5
6
'new test.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'new test.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
Run-Time Check Failure #2 - Stack around the variable 'Test' was corrupted.
A buffer overrun has occurred in new test.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.

For more details please see Help topic 'How to debug Buffer Overrun Issues'. 


this is what error I get once it runs
take out the ; at the end of: #include <iostream>

the rest is fine, I just compiled it.
It sort of worked but I sometimes still get a blank black screens and the array wont load?
shows no errors
plz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//Quicksort(Test,0,10);
// calls Pivot(Test, 0, 10);

int Pivot(int info[],int left,int right){
   int temp; //look, indentation
   int p=info[left];
   int l=left-1; //l=-1
   int r=right+1; //r=11

   while(l < r){
      if(info[r] < p){ //out of bounds
         r--;	
      }

      if(info[l] > p){ //out of bounds
         l++;
      }
Last edited on
I did left+ 1 and right -1 but same problem
If you do `left+1' then you are not considering `Test[0]'
Topic archived. No new replies allowed.