### arrays and card shuffling

so im taking an introductory compsci class and its not introductory. its pretty rough for a beginner coder like myself. so this is my hw: took me a while to get this far.
i have to do monge's shuffle.and a bit more. im sure you can look it up on google. and use these functions.
void mongeShuffle(int A[], int B[], int n) which accepts two equal size arrays and applies the Monge shuffle procedure to the firrst n elements of A and places them in the fi rst n positions of B. (Make sure that when calling this function B's elements are not important and can be overwritten during the shuffling.)
2. int cycleLength(int A[], int n) which returns the smallest number (greater than zero)of Monge shuffles that must be applied to A in order for the resulting order to be equal to A. I.e, how many shuffles does it take to get back to the original ordering?
3. bool isTotalShuffleCycle(int A[], int n) which returns true if all of the shuffles applied A are always total. A total shuffle is one in which every shuffled element is in di fferent position than its original starting position.
Your program should repeatedly ask the user for the number n (at least 2 and at most 1000) of items to shuffle and perform the tasks listed below. If they enter a number outside of this range the program terminates.

sample:
How many items in the sequence? 19
Initial Ordering:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Ordering after one shuffle:
17 15 13 11 9 7 5 3 1 0 2 4 6 8 10 12 14 16 18
It took 18 shuffles to restore array back to its original order.
Not all the shuffles in the cycle were total.

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 #include #include using namespace std; void mongeShuffle(int A[], int B[], int n) { int count = 0; /*for (int j=0; j=0; k--) { if(k%2 == 1) B[(n-k-1)/2]= A[k]; else if(k%2 == 0) B[(k/2)+n/2] = A[k]; } /* for (int l=0; l=2 || n<=1000) { cout << "How many items in the sequence?: "; cin >> n; if(n>=2 || n<=1000) { int A[SIZE]; int B[SIZE]; for (int i=0; i

the problem is you are keep Shuffleing the original array again and again and it is not comming out of while loop.
you should store your original array to some C[SIZE] and after Shuffle copy the Shuffled containt from B[] to A[].
and then compair A[] and C[] in function cycleLength in for loop.

hope you got the point.
Last edited on
Topic archived. No new replies allowed.