VISUAL C++ Question
Hi,
I have array of 3 elements and I want to shift its elements to the right and replace the shifted index cell with "SHIFTED" string and this should loop until all the cells has "SHIFTED" string.
For example:
int a[x]={0,1,2};
Initial index and elements Order:
[0]=0
[1]=1
[2]=2
should become in the:
1st loop:
[0]=SHIFTED
[1]=0
[2]=1
2nd Loop:
[0]=SHIFTED
[1]=SHIFTED
[2]=0
3rd Loop:
[0]=SHIFTED
[1]=SHIFTED
[2]=SHIFTED
I know I can do that with memmove() but I don't want to use any function in it.
Would you please help me; here is my work:
#include <iostream>
#include <string>
#include <stdio.h>
#include <cstdlib>
using namespace std;
int const ARRAY_SIZE=3;
int main()
{
int Array[ARRAY_SIZE];
int iniPostion,newPostion;
string x="SHIFTED";
for(iniPostion=0; iniPostion<ARRAY_SIZE; iniPostion++)
{
Array[iniPostion] = iniPostion;
cout << "Cell [" << iniPostion << "] Initial Element is: (" << Array[iniPostion] << ")" << endl;
}
cout << endl;
for(newPostion=0; newPostion<ARRAY_SIZE; newPostion++)
{
Array[newPostion]=newPostion;
cout << "Cell [" << newPostion << "] New Element is: (";
if(Array[newPostion-1]<0)
{
cout << x << ")\n";
}
else
{
cout << Array[newPostion-1] << ")" << endl;
}
}
return 0;
}