how to rotate elements to the left in array?



im trying to rotate an array to the left for example rotateLeft3([1, 2, 3]) → [2, 3, 1]

here is my soultuion but its not working for some reason. Can someone please explain what im doing wrong ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
include<iostream>

using namespace std;
int main()

{
	
	bool six;
	int Array[3] = { 1,2,3 };
	int x = sizeof(Array) / sizeof(Array[0]);
	int temp = Array[0];
	int temp2;
	for (int i = 0; i < x; i++)

	{


	
		Array[i] = Array[i + 1];
		Array[x - 1] = temp;
	

	}


	for (int i = 0; i < 3; i++)

	{


		cout << Array[i] << endl;
	}
		system("pause");

		return 0;


	}
Line 1 should be: #include <iostream> otherwise it doesn't compile.
What is the purpose of lines 8 and 12?
Line 9 should be int Array[] = { 1,2,3 };
Line 26 should be for (int i = 0; i < x; i++).
Finally, the bug is in lines 13-23, which should be:
1
2
3
4
5
	for (int i = 0; i < (x - 1); i++)
	{
		Array[i] = Array[i + 1];
	}
	Array[x - 1] = temp;

Topic archived. No new replies allowed.