question about in -place sort

Posted by davit-datuashvili on Stack Overflow See other posts from Stack Overflow or by davit-datuashvili
Published on 2010-05-30T13:17:02Z Indexed on 2010/05/30 13:22 UTC
Read the original article Hit count: 173

Filed under:

for example we have following array

char data[]=new char[]{'A','S','O','R','T','I','N','G','E','X','A','M','P','L','E'};

and index array

int  a[]=new int[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}:


   void insitu(char data[],int  a[],N){
 for (int i=0;i<N;i++)
{
    char v=data[i];
int j,int k;
for (k=i;a[k]!=i;k=a[j];a[j]=j)
{
   j=k;data[k]=data[a[k];
}
  data[k]=v; a[k]=k;
}

i have question what is initialize value of j? when i run this code it asks me to initialize j and what should do?

}

© Stack Overflow or respective owner

Related posts about algorithm