Я пытаюсь написать функцию func1, которая может уникально перемешивать заданную колоду карт (массив), учитывая две другие колоды, начальную колоду и полученную колоду. Например, колода карт [1, 2, 3, 4, 5] перемешивается и производит еще одну колоду карт [4, 5, 2, 1, 3]. Я хочу завершить тот же случайный случай (положить карту в слот 0 в слот 3, карту в слот 1 в слот 2 и т. Д.), Но на этот раз в другую колоду карт [2, 3, 1, 5, 4]. Он должен распечатать [5, 4, 3, 2, 1], если я написал код правильно. Хотя он запускает программу, он правильно печатает только первую «карточку», а остальные действительно большие цифры. Что я сделал не так? Я использую правильный подход, или я должен переосмыслить свой дизайн?
#include <iostream>
using namespace std;
int * func1(int *deck) // A unique shuffle given two decks, a starting and ending deck (in this case, "start" and "shuff1")
{
int start[5] = { 1,2,3,4,5 }; // Starting deck
int shuff1[5] = { 4,5,2,1,3 }; // Resulting deck after shuffle. This is the specific type of shuffle that we are copying
int finish[5] = {}; // The deck that we are returning
for (int i = 0; i < 5; i++) // Looks at a specific spot (i) in the start deck...
{
for (int j = 0; j < 5; j++) // Looks through all the spots (j) in the shuff1 deck...
{
if (start[i] == shuff1[j]) // And if the cards themselves are identical, then it takes the ith card
{ // in the given deck and puts it in the jth spot in the finish deck
int temp = deck[i];
finish[j] = temp;
j = 5;
}
}
}
return finish;
}
int main()
{
int test[5] = { 2,3,1,5,4 }; // Given deck
int* shuff2 = func1(test); // Calls a specifc shuffle and sets it equal to a deck called shuff2
for (int i = 0; i < 5; i++)
{
cout << shuff2[i] << endl; // Prints shuff2
}
return 0;
}