fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // void rotatearray(int **arr,int l){
  5. // int *temparr=new int[l];
  6. // for(int i=0; i<l-1; i++){
  7. // temparr[i+1]=(*arr)[i];
  8. // }
  9. // temparr[0]=(*arr)[l-1];
  10. // (*arr)=temparr;
  11. // }
  12.  
  13. void rotatearr(int **arr, int l){
  14. int lastelement=(*arr)[l-1];
  15. for(int i=l-1; i>=1; i--){
  16. (*arr)[i]=(*arr)[i-1];
  17. }
  18. (*arr)[0]=lastelement;
  19. }
  20.  
  21. int main(){
  22. int *arr=new int[10]{1,2,3,5,7,8,5,4};
  23. rotatearr(&arr,8);
  24. for(int i=0; i<8; i++){
  25. cout<<arr[i]<<" ";
  26. }
  27. }
  28.  
Success #stdin #stdout 0.01s 5508KB
stdin
Standard input is empty
stdout
4 1 2 3 5 7 8 5