这是什么类型的? [英] What kind of sort is this ?

查看:73
本文介绍了这是什么类型的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 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 ?

推荐答案

学会正确缩进你的代码,它显示它的结构,它有助于阅读和理解。它还有助于发现结构错误。

Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
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] ;
  }
}



专业程序员的编辑器具有此功能以及其他功能,例如括号匹配和语法高亮。

Notepad ++ Home [ ^ ]

ultraedit [ ^ ]


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.


这篇关于这是什么类型的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆