单次排序

    xiaoxiao2021-04-17  42

    #include "stdafx.h" int main() { int a[6] = {5,2,7,6,3,1}; int temp = 5; int p=0, q=5; while (p != q)//一右一左 { while (a[q] > temp && p!=q) //p!=q是为了不让p,q错过 q--; a[p] = a[q]; while (a[p] < temp && p!=q) p++; a[q] = a[p]; } a[p] = 5; for (int i = 0;i < 6;i++) printf("%d ",a[i]); while (1); return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-673944.html

    最新回复(0)