Skip to content

Commit 2f4efa7

Browse files
authored
Merge pull request #30 from satishguptaji/patch-2
File for split and add
2 parents eb5540a + 129f2ef commit 2f4efa7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

split-and-add.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
// CPP program to split array and move first
3+
// part to end.
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
7+
void splitArr(int arr[], int n, int k)
8+
{
9+
for (int i = 0; i < k; i++) {
10+
11+
// Rotate array by 1.
12+
int x = arr[0];
13+
for (int j = 0; j < n - 1; ++j)
14+
arr[j] = arr[j + 1];
15+
arr[n - 1] = x;
16+
}
17+
}
18+
19+
// Driver code
20+
int main()
21+
{
22+
int arr[] = { 12, 10, 5, 6, 52, 36 };
23+
int n = sizeof(arr) / sizeof(arr[0]);
24+
int position = 2;
25+
26+
splitArr(arr, 6, position);
27+
28+
for (int i = 0; i < n; ++i)
29+
printf("%d ", arr[i]);
30+
31+
return 0;
32+
}

0 commit comments

Comments
 (0)