I'm trying to rotate an array of ints by one element to the left. I'm a
newbie on this so please have a little patience...
I want to rotate the array so if I have 12345, after one rotation I get
23451 and after another I get 34512.
I'm getting the following output after three rotations:
12345
23452
34523
45234
2007-01-27
07:24:17
·
1 answers
·
asked by
Anonymous
in
Computers & Internet
➔ Programming & Design
const int MAX_SIZE=5;
int MyArray[MAX_SIZE];
void shiftLeft(int tmparr[MAX_SIZE]);
void PrintArray(int tmparr[MAX_SIZE]);
int main(int argc,char *argv[])
{
for(int i=0;i
{
MyArray[i]=i+1;
}
PrintArray(MyArray);
shiftLeft(MyArray);
PrintArray(MyArray);
shiftLeft(MyArray);
PrintArray(MyArray);
shiftLeft(MyArray);
PrintArray(MyArray);
system("Pause");
}
void shiftLeft(int tmparr[MAX_SIZE])
{
for(int i=0;i
{
MyArray[i]=tmparr[(i+1)%MAX_SIZE];
}
}
void PrintArray(int tmparr[MAX_SIZE])
{
for(int i=0;i
{
cout<<"Array position: "<
cout<<"Contents: "<
}
cout<<"\n\n
********************************************************"<
2007-01-27
07:25:26 ·
update #1