快排说的很邪乎,原理懂了,实现自然也就出来了;

public void static quickSorted( int[] a ,int low ,int high){

//递归结束条件

if(low>=hih){  return ;  }

int i=low; int j=high int base=a[low];

int temp=0;

while(i<j){

  while(i<j&&a[j]>base){

    j--;

  }

  while(i<j&&a[i]<base){

    i++;

  }

  //交换数值

  temp=a[i];

  a[i]=a[j];

  a[j]=temp;

 

}

  //调整base位置

  temp=a[low];

  a[ilow]=a[i];

  a[i]=temp;

  //递归调用

  //左边递归

  quickSorted(a,0,i-1);

  //右边递归

  quickSorted(a,i+1,high);

  }

      整个思路捋顺了,代码就非常简单了。去面了几家互联网公司才明白,尼玛数据结构和算法才是重点,还好,哥也不是怨天尤人的人,开个专栏 重新复习下原来的东西,有需要的人还可以看看。

 

相关文章:

  • 2021-08-18
  • 2022-02-13
  • 2021-06-15
  • 2022-12-23
  • 2021-12-18
  • 2021-07-12
  • 2021-06-19
猜你喜欢
  • 2022-01-20
  • 2021-09-30
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2021-05-16
  • 2022-01-24
相关资源
相似解决方案