×

# Please Tell me my mistake in this program

 0 I've made this program as the demonstration of Quick Sort. I've defined it for 5 inputs but it is taking infinite. please tell me the Mistake in it. #include using namespace std; int a[5]; void QSort(int,int); int Divide(int,int); int main() { int i; cout<<"Enter Elements : "<>a[i];} QSort(0,4); cout<<"Sorted Elements are : "<=pivot)&&(right>left)) right--; if(left

 3 > but it is taking infinite while(true) { ...  of course, as your while loop never ends ! :) answered 27 Apr '12, 18:10 3.4k●2●19●55 accept rate: 20% But while taking input, it should not me redirected to the while loop. it should be in main function only. because i am not calling any function there. (07 May '12, 15:31) appy29050★ But you call QSort() in the main() , and in qsort function you call Divide, so it'll start an loop while(true) without any break inside, and it won's finish ;-) (14 May '12, 17:49)
 0 you have define int a[5] outside the main function. answered 10 Apr '17, 15:36 1 accept rate: 0% 1 does that really matter? I'll show you codes where i declare array of size upto 10^6 outside main funtion which called as global declaration in programming languages (10 Apr '17, 16:27)
 0 Remove the while(true) condition with the correct condition and you're good to go ! :) answered 10 Apr '17, 22:07 419●2●10 accept rate: 7%
 0 the program is not taking input infinite times. the program enters into a infinite loop inside the while() loop in the function Divide() because there is no terminating condition in that loop. add a terminating condition inside the while() loop so that the program an terminate. answered 10 Apr '17, 22:54 11 accept rate: 0%
 0 You have used an infinite loop...while(true) instead of true place the correct condition for loop termination answered 10 Apr '17, 22:55 41●1 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,911

question asked: 27 Apr '12, 13:54

question was seen: 2,439 times

last updated: 10 Apr '17, 22:55