I have 2 constructor functions and 2 additional function:

`declare: d,d' = deck; c, c' = card`

Constructor 1)

`CreateDeck();`

Constructor 2)

`addCard(d,c); `

additional 1)

`addCardRandomly(d', c');`

additional 2)

`CardsInTheDeck(d'); (it returns "CardsInTheDeck(d)+1" when called with addCard(d,c) constructor obviously) `

now, what happens when the function `addCardRandomly(d',c')`

is called with the `addCard(d,c)`

constructor? This is the semantic specification given by the book:

`if random(CardsInTheDeck(d') = CardsInTheDeck(d')+1): then addCard(d',c'); else addCard(addCardRandomly(d, c'), c); `

What I think it does is: Given that a deck of card can be treated as a queue, we can take the card c that our constructor has to insert inside the deck and: if the random gives back the first position of the queue then simply put the card on that position;

else swap that card with the card we just randomized and insert the cards over the card in that position once at time over the card we randomized itself. Eg:

Cards are 1 2 3 4 5 6 7 8

We have to insert 9

**if** random = 5

it becomes 1 2 3 4 **9** 5 6 7 8

(case where random = 9 omitted because trivial)

Is it correct? What makes this recursive specification so complex? How can i visualize and understand this kind of ideas generally? How can I explain this concept once the final solution is met? This looks so complex to me. Thanks!