Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!