Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,061 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,589 people online right now. Registration is fast and FREE... Join Now!




2d array element shifts

 
Reply to this topicStart new topic

2d array element shifts, row and col shifts

mrgreen27
22 Apr, 2008 - 02:38 AM
Post #1

New D.I.C Head
*

Joined: 22 Apr, 2008
Posts: 1

in working with my 2d arrays, i have to read in from an input file a char array of NxN and manipulate the matrix in various ways. i have gotten just about everything finished, except i cannot figure out the logic of shifting a row left or right, or shifting a column up or down.

i know i have to temporarily store the last element in a row or column, and then i get stuck on figuring out moving an element from there. i have this for trying to shift a row right that the user specifies. this part here ends up reversing the elements of the row instead of shifting them. n is the size of an NxN matrix.

CODE

for(int i=0; i<n/2; i++)
{
    temp = matrix[row][n-i-1];
    matrix[row][n-i-1] = matrix[row][i];
    matrix[row][i] = temp;
}

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 06:30PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month