can u fix it. my code is working for some numbers but when i type 3digit no itis not working | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

can u fix it. my code is working for some numbers but when i type 3digit no itis not working

this is quick sort program it is working for only some digits, can u help me please #include<iostream> using namespace std; class K{ public: void swap(int *i,int *j){ int temp; temp=*i; *i=*j; *j=temp; } int partition(int a[],int low , int high){ int i=-1; int pivot=high; for(int j=low;j<high;j++){ if(a[j]<=a[pivot]){ i++; swap(&a[i],&a[j]); } } swap(&a[i+1],&a[high]); return(i+1); } void quick(int a[],int start,int end) { if(start<end){ int ip= partition(a,start,end); quick(a,start,ip-1); quick(a,ip+1,end); } } }; main(){ int n,j; cout<<"enter the range for quick sorting"; cin>>n; int a[n]; for(j=0;j<=n-1;j++){ cout<<"enter element"; cin>>a[j]; } K obj; obj.quick(a,0,n-1); cout<<"displaying sorted array"; for(j=0;j<=n-1;j++){ cout<<a[j]; } }

28th Oct 2018, 1:49 PM
Indradharmatej Reddy
Indradharmatej Reddy - avatar
5 Answers
0
Your code is too much complicated and uses very large computational power and when array is bigger than 5 elements the Stack memory completely get exhausted and program crash. The data of the class must be inside of the class and utility functions are in the private area of the class. I'll improve it just wait. Where's from you learnt C++?
10th Oct 2019, 4:55 PM
C ++
C ++ - avatar
0
https://code.sololearn.com/chF7EO1WenvY Here is the solution but it is tooooo much processing consuming..........
11th Oct 2019, 5:22 AM
C ++
C ++ - avatar
11th Oct 2019, 6:00 AM
C ++
C ++ - avatar
- 1
Please always send code link. not copy paste.. it is difficult to debug.
10th Oct 2019, 3:35 PM
C ++
C ++ - avatar
10th Oct 2019, 4:07 PM
C ++
C ++ - avatar