Click here to Skip to main content
15,887,337 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
 int x[] = { 123 , 999 , 456 , 3432 , 12 , 43 , 9 , 67 , 9000 , 12345 , 45678 , 789 , 765 , 321 } ;
    
int x1[] = { 123 , 999 , 456 , 3432 , 12 , 43 , 9 , 67 , 9000 , 12345 , 45678 , 789 , 765 , 321 } ;

  for ( int i=0 ; i<=4 ; i++ ) 
    {
      int c=0  ; 

     for ( int k=0  ; k<10 ;k++)
      {
      for ( int a=0 ; a<x.length ; a++ )
      {
          if ( ( x1[a] / ( (int)( Math.pow(10,i) ) ) ) %10 == k ) 
          {        
   
             x[c] = x1[a] ;                  

 System.out.println(x[c] + "      " + c );                
           c++ ;  
          }                                     
        }
      
      }
    
     for ( int u=0 ; u<x1.length  ; u++ )
    {
      x1[u] = x[u] ;       
    }

    }


What I have tried:

I was trying to implement radix sort and ended up with this in first try . I removed the temporary array since it is not required when I checked carefully . Is it a good algorithm and what kind of sort is it ?
Posted
Updated 10-Jan-18 10:06am

1 solution

Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
Java
int x[] = { 123 , 999 , 456 , 3432 , 12 , 43 , 9 , 67 , 9000 , 12345 , 45678 , 789 , 765 , 321 } ;
int x1[] = { 123 , 999 , 456 , 3432 , 12 , 43 , 9 , 67 , 9000 , 12345 , 45678 , 789 , 765 , 321 } ;
for ( int i=0 ; i<=4 ; i++ )
{
  int c=0  ;
  for ( int k=0  ; k<10 ;k++)
  {
    for ( int a=0 ; a<x.length ; a++ )
    {
      if ( ( x1[a] / ( (int)( Math.pow(10,i) ) ) ) %10 == k )
      {
        x[c] = x1[a] ;
        System.out.println(x[c] + "      " + c );
        c++ ;
      }
    }
  }
  for ( int u=0 ; u<x1.length  ; u++ )
  {
    x1[u] = x[u] ;
  }
}

Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]
Quote:
Is it a good algorithm and what kind of sort is it ?

It look like a radix sort but highly inefficient.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900