Lexicographic algorithm
I'm trying to make this algorithm work, but it keeps telling me that my declaration array is not correct because it needs to have a constant value. Array declaration can be found in the main
#include<iostream>
#include<array>
using namespace std;
void nextPermutation(char* v, int n) { //function declaration for next permutation
int i, j; //variable declaration
for (i = n - 1; i > 0 && v[i - 1] >= v[i]; i--); // we go to the index till v[i]>v[i-1]
if (i > 0) { //if i is greater than 0 than we have atleast one possible next permutation
for (j = i; j <= n - 1 && v[j] > v[i - 1]; j++); // we find the largest element after index i
swap(v[i - 1], v[j - 1]); // we swap it after we find it
}
j = n - 1; //j is assigned the last element
while (i < j) { //we reverse the order from i to j element
swap(v[i], v[j]);
i++;
j--;
}
}
int main()
{
int n; //variable for the data lenght
cout << "Enter the size of the array input numerical or string: ";
cin >> n;
char v[n]; //array declaration
for (int i = 0; i < n; i++)cin >> v[i]; //input in the array
nextPermutation(v, n); //function called
for (int i = 0; i < n; i++)cout << v[i] << " "; //display the output
return 0;
}`