@@ -158,4 +158,72 @@ public class rotateTile {
158158 }
159159 }
160160}
161+ ```
162+ ## C++ Implementation
163+
164+ ### [ Solution] ( ./C++/rotateTile.cpp )
165+ ``` cpp
166+ /* *
167+ * @author : Rajdeep Roy Chowdhury<rrajdeeproychowdhury@gmail.com>
168+ * @handle : razdeep
169+ * @date : Feb 17, 2019
170+ */
171+ #include < bits/stdc++.h>
172+ std::vector<std::vector<int >> rotate (std::vector< std::vector<int > > &two_D_array)
173+ {
174+ std::vector< std::vector<int > > result(two_D_array.size());
175+ for(int i=0; i<two_D_array.size();i++)
176+ {
177+ std::vector<int > this_array(two_D_array.size(), 0);
178+ result[ i] = this_array;
179+ }
180+ int rj = two_D_array.size() - 1, ri = 0;
181+ for (int i = 0; i < two_D_array.size(); i++)
182+ {
183+ for (int j = 0; j < two_D_array[ i] .size(); j++)
184+ {
185+ result[ ri++] [ rj ] = two_D_array[ i] [ j ] ;
186+ }
187+ rj--;
188+ ri = 0;
189+ }
190+ return result;
191+ }
192+ int main(int argc, char ** argv)
193+ {
194+ int n;
195+ std::cout << "Enter the value of n ";
196+ std::cin >> n;
197+ std::vector< std::vector<int > > two_D_array(n);
198+ for (int i = 0; i < n; i++)
199+ {
200+ std::vector<int > this_array(n, 0);
201+ // std::vector<int > this_array = new std::vector<int >(n);
202+ for (int j = 0; j < n; j++)
203+ {
204+ std::cin >> this_array[ j] ;
205+ }
206+ two_D_array[ i] = this_array;
207+ }
208+ std::cout << "Original Matrix is..." << std::endl;
209+ for (int i = 0; i < two_D_array.size(); i++)
210+ {
211+ for (int j = 0; j < two_D_array[ i] .size(); j++)
212+ {
213+ std::cout << two_D_array[ i] [ j ] << " ";
214+ }
215+ std::cout << std::endl;
216+ }
217+ std::vector< std::vector<int > > rotated_2d_array = rotate(two_D_array);
218+ std::cout << "Rotated matrix is" << std::endl;
219+ for (int i = 0; i < two_D_array.size(); i++)
220+ {
221+ for (int j = 0; j < two_D_array[ i] .size(); j++)
222+ {
223+ std::cout << rotated_2d_array[ i] [ j ] << " ";
224+ }
225+ std::cout << std::endl;
226+ }
227+ return 0;
228+ }
161229```
0 commit comments