leetcode Sort Colors

来源:互联网 发布:局域网行为控制软件 编辑:程序博客网 时间:2024/06/03 23:48

根据题意,选择直接插入排序


代码

class Solution {public:    void sortColors(int A[], int n) {                if(n==0||n==1)            return;                for(int i = 1; i < n; ++i)            for(int j = i; j > 0; j--)            {                if(A[j]<A[j-1])                {                    int temp = A[j];                    A[j] = A[j-1];                    A[j-1] = temp;                }            }            }};


0 0