Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<math.h>
- using namespace std;
- int n=7,i;
- int arr[7]={8,1,6,2,4,2,5};
- int cnt=0;
- int StoogeSort(int a[],int start,int end){
- int temp,temp2;
- cnt++;
- cout<<cnt<<")=[ ";
- for(i=0;i<n-1;i++){
- cout<<arr[i]<<",";
- }
- cout<<arr[n-1];
- cout<<"]"<<endl;
- if(a[end]<a[start]){
- temp=a[start];
- a[start]=a[end];
- a[end]=temp;
- }
- if(start+1>=end)
- return 0;
- //if(end-start+1>2){
- // temp2=ceil((float)(end-start+1)/(float)3);
- temp=floor((float)(end-start+1)/(float)3);
- // cout<<"ceil="<<temp<<" floor="<<temp2<<endl;
- StoogeSort(a,start,end-temp);
- StoogeSort(a,start+temp,end);
- StoogeSort(a,start,end-temp);
- }
- int main(){
- //cout<<"Enter n=";
- //cin>>n;
- /* cout<<"Enter elements";
- for(i=0;i<n;i++){
- cin>>arr[i];
- }
- */
- StoogeSort(arr,0,n-1);
- cout<<"Sorted DAta";
- for(i=0;i<n;i++){
- cout<<"->"<<arr[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment