Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Shuffle linked list in C??? I have to create a program that plays the game of UNO. We have to create the deck using a

Shuffle linked list in C???

I have to create a program that plays the game of UNO. We have to create the deck using a linked list, and also be able to shuffle the cards. I have a hard time fully understanding linked lists. I found a shuffle and swap function online and I am currently using it in my code, but I think the shuffle function is off. The output is only "shuffling" large portions of the deck, not each individual card.

If you can see what is wrong with my code and correct it, or even offer a better shuffle function, that would be awesome!

Here is a picture of my code:

image text in transcribedimage text in transcribed

#include 10 #include 11 #include 12 13 typedef struct card s f 14 15 16 17 18card; 19 20 void print_list(card headp) char suit [71; int value; char action[15]; struct card s *pt while (headp NULL){ %s != ", headp->suit, headp->value, headp->action); printf("%s %d headp headp->pt: 25 printf("n") 27 void swap_cards(card* source, card target) if (source != NULL && target != NULL){ char tmpSuit[71; strcpy(&tmpSuit, source->suit) int tmpVal = source->value; char tmpAct[15] strcpy(&tmpAct, source->action); strcpy(source->suit, target->suit); source->value arget->value; strcpy(source->action, target->action); strcpy(target->suit, &tmpSuit) target->value mpval ; strcpy(target->action, &tmpAct); 30 Incompatible pointer types pas 32 Incompatible pointer types pass 35 Incompatible pointer types passing 38 Incompatible pointer types passing 'cl 40 41 44 //FIXME Kind of shuffles cards. More like reorganizes some parts, doesn't randomly shuffle suffiently 45 void shuffle cards (card *deck) intn1880, i; int decksize- 186; card *tmp = deck ; while (n>0) while (tmp != NULL){ card *target- deck; i = rand ( )%decksize; 52 while (1--&& tmp != NULL){ 54 target = target->pt; swap_cards(tmp, target) tmp = tmp->pt; #include 10 #include 11 #include 12 13 typedef struct card s f 14 15 16 17 18card; 19 20 void print_list(card headp) char suit [71; int value; char action[15]; struct card s *pt while (headp NULL){ %s != ", headp->suit, headp->value, headp->action); printf("%s %d headp headp->pt: 25 printf("n") 27 void swap_cards(card* source, card target) if (source != NULL && target != NULL){ char tmpSuit[71; strcpy(&tmpSuit, source->suit) int tmpVal = source->value; char tmpAct[15] strcpy(&tmpAct, source->action); strcpy(source->suit, target->suit); source->value arget->value; strcpy(source->action, target->action); strcpy(target->suit, &tmpSuit) target->value mpval ; strcpy(target->action, &tmpAct); 30 Incompatible pointer types pas 32 Incompatible pointer types pass 35 Incompatible pointer types passing 38 Incompatible pointer types passing 'cl 40 41 44 //FIXME Kind of shuffles cards. More like reorganizes some parts, doesn't randomly shuffle suffiently 45 void shuffle cards (card *deck) intn1880, i; int decksize- 186; card *tmp = deck ; while (n>0) while (tmp != NULL){ card *target- deck; i = rand ( )%decksize; 52 while (1--&& tmp != NULL){ 54 target = target->pt; swap_cards(tmp, target) tmp = tmp->pt

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

LO 182 Are there diff erent kinds of memory?

Answered: 1 week ago

Question

3 How supply and demand together determine market equilibrium.

Answered: 1 week ago

Question

1 What demand is and what affects it.

Answered: 1 week ago