Leetcode-922 Sort Array By Parity II(按奇偶排序数组 II)

 1 class Solution
 2 {
 3     public:
 4         vector<int> sortArrayByParityII(vector<int>& A)
 5         {
 6             stack<int> oddList;
 7             stack<int> evenList;
 8             
 9             for(auto d:A)
10                 if((d&0x1)==1)
11                     oddList.push(d);
12                 else
13                     evenList.push(d);
14             
15             vector<int> result;
16             while(!oddList.empty())
17             {
18                 result.push_back(evenList.top());
19                 result.push_back(oddList.top());
20                 evenList.pop();
21                 oddList.pop();
22             }
23             return result;
24         }
25 };
原文地址:https://www.cnblogs.com/Asurudo/p/9799817.html