I think that we have to make a spiral traversal So o/p for your matrix would be: 1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5, 6, 7, 11, 10
On Thu, Jul 28, 2011 at 1:56 PM, Rajeev Kumar <rajeevprasa...@gmail.com>wrote: > @puneet > > Can you give us an example what u mean by 180 degree rotation........... > For given matrix like > 1, 2, 3, 4 > 5, 6, 7, 8 > 9,10,11, 12 > 13,14,15,16 > > What is the expected output? > > > On Wed, Jul 27, 2011 at 11:29 PM, Puneet Gautam > <puneet.nsi...@gmail.com>wrote: > >> Can anyone give an O(n) solution pls...?? >> I think the above code is an O(n^2) solution.. >> if i am not wrong...!!! >> >> >> >> On 7/27/11, amit <amit.codenam...@gmail.com> wrote: >> > #include <cstdio> >> > #include <algorithm> >> > using namespace std; >> > >> > const int MX = 1000; >> > int n, m; >> > int a[MX][MX]; >> > >> > int main() { >> > scanf("%d%d", &n, &m); >> > for(int i = 0; i < n; i++) >> > for(int j = 0; j < m; j++) >> > scanf("%d", &a[i][j]); >> > >> > for(int i = 0; i < n/2; i++) >> > for(int j = 0; j < m; j++) >> > swap(a[i][j], a[n-i-1][m-j-1]); >> > if(n&1) >> > for(int j = 0; j < m/2; j++) >> > swap(a[n/2][j], a[n/2][m-j-1]); >> > >> > for(int i = 0; i < n; i++) { >> > for(int j = 0; j < m; j++) >> > printf("%d ", a[i][j]); >> > printf("\n"); >> > } >> > } >> > >> > >> > On Jul 27, 7:54 pm, Anika Jain <anika.jai...@gmail.com> wrote: >> >> is it lyk for {1,2,3 >> >> 4,5,6, >> >> 7,8,9} >> >> to be {3,2,1, >> >> 6,5,4, >> >> 9,8,7} ?? >> >> >> >> >> >> >> >> On Wed, Jul 27, 2011 at 9:37 AM, Deoki Nandan <deok...@gmail.com> >> wrote: >> >> > rotate a 2D matrix by angle 180 >> >> >> >> > -- >> >> > **With Regards >> >> > Deoki Nandan Vishwakarma >> >> >> >> > * >> >> > * >> >> >> >> > -- >> >> > You received this message because you are subscribed to the Google >> >> > Groups >> >> > "Algorithm Geeks" group. >> >> > To post to this group, send email to algogeeks@googlegroups.com. >> >> > To unsubscribe from this group, send email to >> >> > algogeeks+unsubscr...@googlegroups.com. >> >> > For more options, visit this group at >> >> >http://groups.google.com/group/algogeeks?hl=en. >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups >> > "Algorithm Geeks" group. >> > To post to this group, send email to algogeeks@googlegroups.com. >> > To unsubscribe from this group, send email to >> > algogeeks+unsubscr...@googlegroups.com. >> > For more options, visit this group at >> > http://groups.google.com/group/algogeeks?hl=en. >> > >> > >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > > > -- > Thank You > Rajeev Kumar > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Tushar Bindal Computer Engineering Delhi College of Engineering Mob: +919818442705 E-Mail : tushicom...@gmail.com Website: www.jugadengg.com -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.