1 Replies - 784 Views - Last Post: 20 April 2010 - 12:30 AM Rate Topic: -----

#1 born2c0de   User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 187
  • View blog
  • Posts: 4,673
  • Joined: 26-November 04

Stooge Sort

Posted 29 October 2005 - 08:34 PM

Description: Shows how an array can be sorted recursively using the Stooge Sort Algorithm.
/*

     STOOGE SORT
     Written by Sanchit Karve AKA born2c0de
     born2c0de AT hotmail DOT com
*/


#include <stdio>

#define ELEMENTS 6

void stoogesort(int A[],int i,int j)
{
   int tmp,k;
   if(A[i]>A[j])
   {
        tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
   }
   if((i+1)>=j)
        return;

   k=(int)((j-i+1)/3);   // Round down
   stoogesort(A,i,j-k);  // First two-thirds
   stoogesort(A,i+k,j);  // Last two-thirds
   stoogesort(A,i,j-k);  // First two-thirds again
}

int main()
{
  int i;
  int X[ELEMENTS]={5,2,4,6,1,3};
  printf("Unsorted Array:n");
  for(i=0;i<ELEMENTS;i++)
            printf("%d ",X[i]);

  stoogesort(X,0,ELEMENTS);
  printf("nSORTED ARRAYn");
  for(i=0;i<ELEMENTS;i++)
            printf("%d ",X[i]);

}



Is This A Good Question/Topic? 0
  • +

Replies To: Stooge Sort

#2 damanik   User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 1
  • Joined: 28-March 10

Re: Stooge Sort

Posted 20 April 2010 - 12:30 AM

Can you help me if that is the name that begins sorted AZ and vice versa? [email protected]
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1