Displaying and rotating arrays

I need this program to rotate the elements in an array to the left, moving the first position to the last position at the same time until the min position returns to its original place. I am stumped as to how to construct the rotate function. How can I achieve this?

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <cstdio>

const int minSize = 1;
const int maxSize = 20;


void welcome();
int getValue(const int minSize, const int maxSize );
void initialize(int arr[ ], int size);
void display(int arr[ ], int size);
void rotate(int arr[ ], int size);


int main()
{
    //array to be rotated
    int dataArray[maxSize];

    //introduce the program to the user
    welcome();

    //let the user pick how much of the array will be used
    int sizeUsed = getValue(minSize, maxSize);

    //initialize the contents in use
    initialize(dataArray, sizeUsed);

    //display the initial content
    display(dataArray, sizeUsed);

    //repeatedly rotate and display the contents
    //until we are back to the original layout
    for(int i = 0; i < sizeUsed; i++) {
            rotate(dataArray, sizeUsed);
            display(dataArray, sizeUsed);
    }

    //end the program
    return 0;
}


void welcome()
{
    printf("Welcome to the array rotation program\n");
    printf("\n");
    printf("This program will initialize an array and then repeatedly rotate its contents\n");
    printf("\n");
}


int getValue(const int minSize, const int maxSize)
{
    bool validData = false;
    int userVal;
    printf("Please selcect an array size in the range 1 to 20\n");
    int scanCount = scanf("%d", &userVal);
    do {
       if(scanCount == 0) {
               printf("That was not a number, please try again\n");
               scanf("%*s");
       } else if((userVal < minSize) || (userVal > maxSize)) {
               printf("That was not within the correct range, please try again\n");
               scanf("%*s");
       } else {
               validData = true;
       }
    }
    while(validData == false);
    return userVal;
}


void initialize(int arr[ ], int size)
{
    for(int i = 0; i < size; i++) {
        arr[i] = i;
    }
}


void display(int arr[ ], int size)
{
   for(pos = 0; pos <= size; pos++) {
           printf("%d", arr[pos]);
   }
}


void rotate(int arr[ ], int size)
{

}
Topic archived. No new replies allowed.