- #1
James889
- 192
- 1
Hi,
i would like some help with this task.
My task is to write a function that shifts an array arbitrary number of steps.
So for example the array { 0,1,2,3,4,5,6,7,8,9 }
would look like { 9,0,1,2,3,4,5,6,7,8 } after the function was called with the steps arguments set to 1.
The actual shifting isn't a problem, but rather how i deal with the last element in the list.
For example if i shift all elements using a for loop
On the last run i am left with temp, containing the last element in the list. How do i put it first?
i would like some help with this task.
My task is to write a function that shifts an array arbitrary number of steps.
So for example the array { 0,1,2,3,4,5,6,7,8,9 }
would look like { 9,0,1,2,3,4,5,6,7,8 } after the function was called with the steps arguments set to 1.
The actual shifting isn't a problem, but rather how i deal with the last element in the list.
For example if i shift all elements using a for loop
Code:
int temp;
for(int i=0; i<length_of_list; i++){
temp = array[i+1];
array[i+1] = array[i];
array[i] = temp;
}
On the last run i am left with temp, containing the last element in the list. How do i put it first?