C++ Program to Split the array and add the first part to the end
There is a given an array and split it from a specified position, and move the first part of array add to the end.

Examples:
Input : arr[] = {12, 10, 5, 6, 52, 36}
k = 2
Output : arr[] = {5, 6, 52, 36, 12, 10}
Explanation : Split from index 2 and first
part {12, 10} add to the end .
Input : arr[] = {3, 1, 2}
k = 1
Output : arr[] = {1, 2, 3}
Explanation : Split from index 1 and first
part add to the end.
// CPP program to split array and move first // part to end. #include <bits/stdc++.h> using namespace std; void splitArr(int arr[], int n, int k) { for (int i = 0; i < k; i++) { // Rotate array by 1. int x = arr[0]; for (int j = 0; j < n - 1; ++j) arr[j] = arr[j + 1]; arr[n - 1] = x; } } // Driver code int main() { int arr[] = { 12, 10, 5, 6, 52, 36 }; int n = sizeof(arr) / sizeof(arr[0]); int position = 2; splitArr(arr, 6, position); for (int i = 0; i < n; ++i) printf("%d ", arr[i]); return 0; } |
chevron_right
filter_none
Output:
5 6 52 36 12 10
Please refer complete article on Split the array and add the first part to the end for more details!
Recommended Posts:
- Create Directory or Folder with C/C++ Program
- C Program to Swap two Numbers
- C++ Program to concatenate two strings using Operator Overloading
- C++ Program to implement Symbol Table
- C++ Program for Bubble Sort
- C++ Program for Heap Sort
- C/C++ Program for n-th Fibonacci number
- C++ Program for ShellSort
- C++ Program for Longest Common Subsequence
- C/C++ Program for Longest Increasing Subsequence
- C++ Program for Longest Increasing Subsequence
- C++ Program for GCD of more than two (or array) numbers
- C++ Program for Common Divisors of Two Numbers
- C++ Program for Bitonic Sort
- C++ Program for Bitonic Sort



