how to rearrange a set of alphabets putting vowel in front follow by the rest of the remaining generated alphabets - i have created the rest of my program but i have zero knowledge on how to even get this started.
my characters are generated from:
srand (time (NULL));
int n = rand () % 26 + 65;
a [i] = static_cast <char> (n);
eg... i have generated from my compiler a set of alphabets (am not using string)
I'm not sure if this would work, but if you are using a string and not a char[], you can call the sort() stl algorithm, passing a predicate to it. The predicate is a function you define, which controls the criteria of the sort. It takes two arguments, each (in this case) would be char.
Basically, in the predicate you'd compare two chars. If you find that one is a vowel and the other isn't you automatically know that the first one is higher. Etc. Here's the documentation on the STL alg if you are interested: http://www.cplusplus.com/reference/algorithm/sort/
Anyway that's how I'd do it.
part 2 after sorting i want it to on the 2nd line display a i a o h j k l m n p q r t - the sorted with AEIOU infront.
i have done part 1 which will generate auto random alphabets now only left with part 2. i have no idea where i should slot it and compute it accordingly.
or rather by using a loop function to swap the array elements so that the vowels are on the left and the right are all the non-vowels.
There are many ways of doing this....one way, given that you have filled a 26 element array randomly is:
1. declare two pointers p1,p2 to the array one to point to array[0] and one to traverse the array until it finds 'a'.
2. swap pointers
3.increment p2 to second element [1] and use p1 to find 'e'.........swap p1 and p2
4.repeat until 'a','e','i','o' and 'u' occupy the first five array elements.
5.sort array from element 5 to element 26 (inclusive)