Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

question 4 * C Program to Perform Stooge Sort 3. */ 4. #include 5. void stoogesort(int [], int, int); 6. 7. void main() 8. {

question 4

* C Program to Perform Stooge Sort 3. */ 4. #include 5. void stoogesort(int [], int, int); 6. 7. void main() 8. { 9. int arr[100], i, n; 10. 11. printf("How many elements do you want to sort: "); 12. scanf("%d", &n); 13. for (i = 0;i < n; i++) 14. scanf(" %d", &arr[i]); 15. stoogesort(arr, 0, n - 1); 16. printf("Sorted array : "); 17. for (i = 0;i < n;i++) 18. { 19. printf("%d ", arr[i]); 20. } 21. printf(" "); 22. } 23. 24. 25. void stoogesort(int arr[], int i, int j) 26. { 27. int temp, k; 28. if (arr[i] > arr[j]) 29. { 30. temp = arr[i]; 31. arr[i] = arr[j]; 32. arr[j] = temp; 33. } 34. if ((i + 1) >= j) 35. return; 36. k = (int)((j - i + 1) / 3); 37. stoogesort(arr, i, j - k); 38. stoogesort(arr, i + k, j); 39. stoogesort(arr, i, j - k); 40. }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

5. What do we mean by integrated capital markets?

Answered: 1 week ago