我写的不设置哨兵的代码为什么第一个元素排不了序呢,而且把判断条件j>0改成j>=0就报错
public class insertSort {
public static void main(String[] args) {
int[] a = {4,5,1,2,6,3};
Sort(a);
System.out.print(Arrays.toString(a));
}
public static void Sort(int[] a) {
for(int i=0;i<a.length-1;i++) {
for(int j=i+1;j>0;j--) {
if(a[j]<a[j-1]) {
int temp = a[j];
a[j] = a[j-1];
a[j-1]=temp;
}
}
}
}