A logical error occurred when implementing the quick sort.
1 #include"header_file.h" 2 using namespace std; 3 4 void swap(int a,int b) 5 { 6 int t; 7 t=a; 8 a=b; 9 b=t;10 }11 12 void quick_sort(int a[],int low,int high)13 {14 15 if(low>=high)16 return;17 18 int first;19 int last;20 first=low;21 last=high;22 23 int x;24 x=a[low];25 26 27 while(low
The execution program will find an infinite loop in the algorithm sorting place. After half a day, it will know the location of 33 and 41 rows. no matter whether the while loop is executed or not, swap statements will be executed. Logical error!
You can only change the method to the most common one.
1 void quick_sort(int a[],int low,int high) 2 { 3 4 if(low>=high) 5 return; 6 7 int first; 8 int last; 9 first=low;10 last=high;11 12 int x;13 x=a[low];14 15 16 while(low
This is not an exchange. assign a value directly and assign a value to a [low.
Very low-level errors