C++ Program to Split the array and add the first part to the end | Set 2 Last Updated : 24 Jan, 2022 Comments Improve Suggest changes Like Article Like Report 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. A O(n*k) solution is discussed here. This problem can be solved in O(n) time using the reversal algorithm discussed below, 1. Reverse array from 0 to n - 1 (where n is size of the array). 2. Reverse array from 0 to n - k - 1. 3. Reverse array from n - k to n - 1. C++ // C++ program to Split the array and // add the first part to the end #include <bits/stdc++.h> using namespace std; /* Function to reverse arr[] from index start to end*/ void rvereseArray(int arr[], int start, int end) { while (start < end) { int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } } // Function to print an array void printArray(int arr[], int size) { for (int i = 0; i < size; i++) cout << arr[i] << " "; } /* Function to left rotate arr[] of size n by k */ void splitArr(int arr[], int k, int n) { rvereseArray(arr, 0, n - 1); rvereseArray(arr, 0, n - k - 1); rvereseArray(arr, n - k, n - 1); } /* Driver program to test above functions */ int main() { int arr[] = { 12, 10, 5, 6, 52, 36 }; int n = sizeof(arr) / sizeof(arr[0]); int k = 2; // Function calling splitArr(arr, k, n); printArray(arr, n); return 0; } Output: 5 6 52 36 12 10 Please refer complete article on Split the array and add the first part to the end | Set 2 for more details! Comment More infoAdvertise with us Next Article C++ Program to Split the array and add the first part to the end | Set 2 kartik Follow Improve Article Tags : C++ Programs C++ DSA Arrays rotation array-rearrange Reverse +3 More Practice Tags : CPPArraysReverse Similar Reads C++ Program to Move all zeroes to end of array | Set-2 (Using single traversal) Given an array of n numbers. The problem is to move all the 0's to the end of the array while maintaining the order of the other elements. Only single traversal of the array is required.Examples:  Input : arr[] = {1, 2, 0, 0, 0, 3, 6} Output : 1 2 3 6 0 0 0 Input: arr[] = {0, 1, 9, 8, 4, 0, 0, 2, 7 2 min read C++ Program to Copy the Contents of One Array Into Another in the Reverse Order Given an array, the task is to copy these array elements into another array in reverse array.Examples: Input: array: 1 2 3 4 5 Output: 5 4 3 2 1 Input: array: 10 20 30 40 50 Output: 50 40 30 20 10 Let len be the length of original array. We copy every element original_arr[i] to copy_arr[n-i-1] to ge 2 min read C++ Program to Find the Minimum and Maximum Element of an Array Given an array, write functions to find the minimum and maximum elements in it. Example: C++ // C++ program to find minimum (or maximum) element // in an array. #include <bits/stdc++.h> using namespace std; int getMin(int arr[], int n) { int res = arr[0]; for (int i = 1; i < n; i++) res = 3 min read Split the array into equal sum parts according to given conditions Given an integer array arr[], the task is to check if the input array can be split in two sub-arrays such that: Sum of both the sub-arrays is equal.All the elements which are divisible by 5 should be in the same group.All the elements which are divisible by 3 (but not divisible by 5) should be in th 8 min read How to Split a String into an Array in C++? In C++, splitting a string into an array of substrings means we have to parse the given string based on a delimiter and store each substring in an array. In this article, we will learn how to split a string into an array of substrings in C++. Example: Input: str= âHello, I am Geek from geeksforgeeks 2 min read C++ Program to Access Elements of an Array Using Pointer Prerequisites: Pointers in C++Array in C++ A Pointer is a variable that stores the memory location or address of an object or variable. In other words, pointers reference a memory location, and obtaining the value stored at that memory location is known as dereferencing the pointer. An Array is the 2 min read C++ Program For Sorting An Array Of 0s, 1s and 2s Given an array A[] consisting 0s, 1s and 2s. The task is to write a function that sorts the given array. The functions should put all 0s first, then all 1s and all 2s in last.Examples: Input: {0, 1, 2, 0, 1, 2} Output: {0, 0, 1, 1, 2, 2} Input: {0, 1, 1, 0, 1, 2, 1, 2, 0, 0, 0, 1} Output: {0, 0, 0, 6 min read How to Read and Write Arrays to/from Files in C++? In C++, an array is a collection of elements of the same type placed in contiguous memory locations. A file is a container in a computer system for storing information. In this article, we will learn how to read and write arrays to/from files in C++. Example: Input: Array = {1, 2, 3, 4, 5}Output: // 2 min read How to Initialize a Set with an Array in C++? In C++, an array stores data in contiguous memory locations and can have duplicates as well whereas a set stores unique elements only in a sorted order. In this article, we will learn how to initialize a set with an array in C++. For Example, Input:arr[]={2, 1, 5, 4, 3, 5};Output:Element in Set are: 2 min read How to Add an Element at the End of List in C++? In C++, the Standard Template Library (STL) has a doubly-linked list container, known as std::list that offers various functions to manipulate elements. In this article, we will learn how to add an element at the end of a list in C++ STL. Example: Input: myList = {1, 2, 3}; Output: List after Elemen 2 min read Like