Hey Guys Can you help me make a Program, Cause this is very hard for me as a newbie. So the program would be like this. Whenever i Entered a Word, for example Airplane, its outcome will become= Aaerplani. So its like the outcome will be jumbled based from the word entered. Im using C languange, Thanks in Advance Programmers
template <class RandomAccessIterator, class RandomNumberGenerator>
void random_shuffle (RandomAccessIterator first, RandomAccessIterator last,
RandomNumberGenerator& gen)
{
iterator_traits<RandomAccessIterator>::difference_type i, n;
n = (last-first);
for (i=n-1; i>0; --i) {
swap (first[i],first[gen(i+1)]);
}
}
First, it is a template function. We can simply drop the first line, but we have to replace the word RandomAccessIterator with a real type. A C-string is an array of characters and thus the real type is char *.
Similarly, the gen is a function that we don't need to pass as parameter.
We have char pointers, so the difference_type can be int.
1 2 3 4 5 6 7 8
void random_shuffle (char * first, char * last)
{
int i, n;
n = (last-first);
for (i=n-1; i>0; --i) {
swap( first[i], first[gen(i+1)] );
}
}
It still depends on functions swap and gen. The usage example of random_shuffle has function myrandom. Can you figure out how to swap values?