SHARE
TWEET

Untitled

a guest Jun 26th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. typedef struct card_s {
  2.     char suit[20];
  3.     int face;
  4.     struct card_s *next, *previous;
  5. } card;
  6.  
  7. card* createHands(card* head, card *cards) {
  8.     card *tail = NULL, *temp = NULL, *temp1;
  9.  
  10.     // Go to end of deck
  11.     while (cards->next != NULL) {
  12.         cards = cards->next;
  13.         }
  14.  
  15.         temp = (card *)malloc(sizeof(card));
  16.         strcpy(temp->suit, cards->suit);
  17.         temp->face = cards->face;
  18.         if (head == NULL) { // If the list for the hand doesn't exist, create head
  19.             head = temp;
  20.         }
  21.         else {
  22.             tail->next = temp;
  23.         }
  24.             tail = temp;
  25.             tail->next = NULL;
  26.  
  27.         temp1 = cards->previous;
  28.         free(cards); // to delete the node added from the deck
  29.  
  30.         cards = temp1;
  31.         cards->next = NULL;
  32.         while (cards->previous != NULL) {
  33.             cards = cards->previous;
  34.         }
  35.  
  36.     return head;
  37.  
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top