LeetCode-Sort Colors

来源:互联网 发布:程序员的思维修炼听书 编辑:程序博客网 时间:2024/06/10 05:46
class Solution {public:    void sortColors(int Array[], int length) {        if(Array==NULL||length<=0)        return ;        int current;    int begin;    int end;        current=begin=0;    end=length-1;        while( current<=end )    {        if( Array[current] ==0 )        {            swap(Array[current++],Array[begin++]);          }        else if( Array[current] == 1 )        {            current++;        }                else //When array[current] =2        {            swap(Array[current],Array[end--]);                    }          }    }};//荷兰国旗问题
0 0
原创粉丝点击