Esempio n. 1
0
 void rotate_helper(vector<vector<int>> &matrix, int s,int e){
     if(s==e)
         return;
     if(s+1==e){
         swap(matrix[s][s], matrix[s][s+1]);
         swap(matrix[s+1][s], matrix[s+1][s+1]);
         swap(matrix[s][s], matrix[e][e]);
         return;
     }
     rotate_helper(matrix, s+1, e-1);
     //左右调换
     int p=s,q=e;
     while(p<=q){
         swap(matrix[s][p], matrix[s][q]);
         swap(matrix[e][p], matrix[e][q]);
         p++;
         q--;
     }
     for(int i=s+1;i<=e-1;i++){
         swap(matrix[i][s], matrix[i][e]);
     }
     //斜调换
     
     for(int k=s+1;k<=e;k++){
         swap(matrix[k][e], matrix[s][s+e-k]);
     }
     for(int k=s+1;k<=e-1;k++){
         swap(matrix[e][k], matrix[s+e-k][s]);
     }
     return;
 }
Esempio n. 2
0
 static typename detail::algorithm_result<ExPolicy, FwdIter>::type
 parallel(ExPolicy const& policy, FwdIter first,
     FwdIter new_first, FwdIter last)
 {
     return detail::algorithm_result<ExPolicy, FwdIter>::get(
         rotate_helper(policy, first, new_first, last));
 }
Esempio n. 3
0
 void rotate(vector<vector<int> > &matrix) {
     rotate_helper(matrix, 0, matrix.size()-1);
 }
Esempio n. 4
0
list_t rotate(list_t list, unsigned int n) {
    return rotate_helper(list, n, list_make());
}
Esempio n. 5
0
static list_t rotate_helper(list_t list, unsigned int n, list_t rotated) {
    if (!n) return append(list, reverse(rotated));
    if (list_isEmpty(list) && n) rotate_helper(reverse(rotated), n-1, list_make());
    return rotate_helper(list_rest(list), n-1, 
        list_make(list_first(list), rotated));
}