Please use C++ and a good detailed solution is much
appreciated!
I have provided code from task 1.3 below
Generate 100 random permutations of the number 1, 2, 3, 4, 5, 6
using of the algorithm you designed for Task 1.3. Store these
permutations into a vector. Search the vector to see if the
permutation 4, 2, 5, 1, 6, 3 is in the vector. Run your program
several times until you found one (would need quite a number of
runs). Here are some examples of generated permutations:
The code from task 1.3 is provided here:
task1_3.cpp file
#include<iostream>
#include<vector>
using namespace std;
#include "permutation.h"
int main() {
srand(time(0));
Permutation p;
p.print();
cout << endl;
}
_______________
Permutation.h file
5 4 1 2 3 6 random calls: 13 2 4 5 1 3 6 random calls: 20 4 6 1 3 2 5 random calls: 18 1 5 6 3 4 2 random calls: 30 2 1 6 5 3 4 random calls: 10 2 1 6 5 3 4 random calls: 12 2 4 6 1 5 3 random calls: 9 5 6 4 3 2 1 random calls: 19 5 1 4 2 6 3 random calls: 18 5 2 1 6 3 4 random calls: 10 5 2 6 1 4 3 random calls: 18 1 3 4 6 5 2 random calls: 16 2 5 1 4 3 6 random calls: 12 6 2 5 3 1 4 random calls: 8 6 2 4 1 5 3 random calls: 9 1 3 2 6 5 4 random calls: 14 1 6 4 2 5 3 random calls: 9 4 2 5 1 6 3 random calls: 13 found it 6 1 2 5 4 3 random calls: 10 3 6 4 2 1 5 random calls: 20 2 1 6 3 5 4 random calls: 6 5 4 1 6 3 2 random calls: 10 1 6 4 5 2 3 random calls: 12 6 4 3 5 1 2 random calls: 16 3 6 4 5 1 2 random calls: 13 4 2 3 1 5 6 random calls: 11 5 2 3 6 1 4 random calls: 10 2 5 4 1 3 6 random calls: 14 6 1 4 2 5 3 random calls: 22 6 5 4 1 2 3 random calls: 11 3 4 1 2 6 5 random calls: 16 1 2 4 5 3 6 random calls: 21 1 You still have to use rand() to create a permutation rather than use other randomisation functions, such as shuffle(), which by nature still calls rand().
Please use C++ and a good detailed solution is much appreciated! I have provided code from task 1.3 below Generate 100 r
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am