java shift elements in array
- by Lightk3ira
Hey I am trying to shift elements forward sending the last element in the array to data[0]. I did the opposite direction but I can't seem to find my mistake in going in this direction.
Pos is users inputed shift times amount
temp is the temporary holder.
data is the array
if(pos 0)
{
do
{
temp = data[data.length -1];
for(int i =0; i < data.length; i++)
{
if(i == data.length-1)
{
data[0] = temp;
}
else
{
data[i+1] = data[i];
}
}
pos--;
}while(pos > 0);
}
Thanks.