vasan.srini
BAN USER- 0of 0 votes
AnswersGiven a matrix represented as int[n][n], rotate it 90 degrees clockwise in-place. (In-place means minimal extra memory to be used, ie, don't make a new array to copy into). Rotate clockwise means top-row becomes right-column, right column becomes bottom-row etc.
- vasan.srini in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding
Repjolenejbrunson0456, Applications Developer at Abs india pvt. ltd.
Hey I am a web writer, also known as a content writer, is a type of writer that produces content ...
RepYorgaKeaton, Area Sales Manager at AMD
Hi, I am Yorga , Information record clerk perform clerical duties that include filing and organising records and collecting information. My ...
RepAdyaKing, Java Experienced at ADP
I am a friendly and outgoing person who enjoys greeting people with a smile. I have more than 5 years ...
RepAahnaAllen, AT&T Customer service email at A9
I am a multilingual Judge with 5 years of combined experience in presiding over court proceedings, prosecuting cases, and tirelessly ...
RepJoshuaChiles, Android test engineer at Accolite software
I am Joshua Information design is an efficient and effective understanding of the information. The term has come to be ...
void rotateMatrix(float** a, int n) {
- vasan.srini October 23, 2012if (n <= 1) {
return; // nothing to do: we hit 0 (n is even) or 1 (n is odd)
}
/* outer layer */
for (int i=0; i<n; i++) {
int saved = a[0][i]; // save top.(left+i)
a[0][i] = a[n-i-1][0]; // move (bottom-i).left to top.(left+i)
a[n-i-1][0] = a[n-1][n-1-i]; // move bottom.(right-i) to (bottom-i).left
a[n-1][n-1-i] = a[i][n-1]; // move top(+i).right to bottom.(right-i)
a[i][n-1] = saved; // move top.left (saved) to top(+i).right
}
rotateMatrix(a[1][1], n-2); // now do it for the inner layer(s)
}