2017-02-23 46 views
-3
public class NIS { 

    public static void insertSort(int[] A) 
    { 
      for(int i = 1; i < A.length; i++) 
      { 
      int value = A[i]; 
      int j = i - 1; 
      while(j >= 0 && A[j] > value) 
      { 
       A[j + 1] = A[j]; 
       j = j - 1; 
      } 
      A[j + 1] = value; 
      } 
     } 
    public static void main(String[] args) { 

     int a[]={20,10,2,100,1}; 
     insertSort(a); 
     for (int i=0 ; i <a.length ; i++) 
     { 
      System.out.println(" "+a[i]); 
     } 

// in this code there are many problems if anyone of you can help me so plz debugg this code. 
    } 

} 
+1

你可以像这样运行它:1)'javac -cp。 NIS.java' 2)'java NIS' –

+1

请在查询这个URL之前询问任何问题:http://stackoverflow.com/help/how-to-ask –

+1

欢迎来到Stack Overflow! “寻求调试帮助的问题(”为什么这个代码不工作?“)必须包含所需的行为,特定的问题或错误以及在问题本身中重现问题所需的最短代码。没有明确问题陈述的问题对其他读者无益。“引自[我可以在这里询问什么主题?](http://stackoverflow.com/help/on-topic)。 –

回答

0

我运行了你的代码,它工作得很好。为了确保,我将它运行在随机生成的大小为20的列表上,整数范围从最大整数大小到最小整数大小,并且每个都可以正常工作。它甚至不会破坏大小为1或0的数组,这对于很多自制排序算法来说可以说是多得多。好工作,快乐编码!

相关问题