This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:discrete:fall2023:projects:cgf0 [2023/10/02 22:56] – [SUITES] dwhite26 | notes:discrete:fall2023:projects:cgf0 [2023/10/05 02:09] (current) – [SUITES] cfoster8 | ||
---|---|---|---|
Line 5: | Line 5: | ||
====VALUES==== | ====VALUES==== | ||
- | A standard deck of playing cards has 52 cards from each of the four suits. There are 13 cards in each suit: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, and King. | + | A standard deck of playing cards has 52 cards from each of the four suits. |
+ | There are 13 cards in each suit: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, and King, from lowest to highest value, and then it loops around. | ||
====SUITES==== | ====SUITES==== | ||
- | The four suits in a standard deck include hearts, diamonds, spades, and clubs. | + | The four suits in a standard deck include hearts, diamonds, spades, and clubs. Spades and clubs are black colored cards, and hearts and diamonds are red. These make up the sub-classes of card types, beyond just their face value. |
===Structure For Doubly Linked List=== | ===Structure For Doubly Linked List=== | ||
Line 17: | Line 18: | ||
{ | { | ||
bool Active; | bool Active; | ||
- | int Rcard; // Card id to call for displaying | + | int cardID; // Card id to call for displaying |
cardnode* next; // Pointer to the next card node | cardnode* next; // Pointer to the next card node | ||
cardnode* prev; // Pointer to the previous card node | cardnode* prev; // Pointer to the previous card node | ||
Line 24: | Line 25: | ||
We originally had just a pointer next for a single linked list but now we have added a pointer for prev. | We originally had just a pointer next for a single linked list but now we have added a pointer for prev. | ||
+ | |||
+ | ===Creating a Doubly-linked List=== | ||
+ | To create our doubly-linked list, we'll undergo a similar process to how we handled our singly-linked list in ttb1. First, we create the first node in our list, then we append onto it. | ||
+ | |||
+ | Creating the first node of the doubly-linked list is almost identical to our previous projects. The only change is that we need to set '' | ||
+ | |||
+ | Adding additional nodes is where it gets more complicated. Before allocating the memory for the next node and moving the current pointer, we'll need to create a temporary pointer (called '' | ||
+ | - Set temp equal to the current pointer | ||
+ | - Allocate the structure memory into '' | ||
+ | - Move the current pointer to the next node. | ||
+ | - Use '' | ||
+ | - Set '' | ||
+ | - Free the memory of '' | ||
+ | To create additional nodes, just repeat these steps. | ||
+ | |||
===Setting Up Buttons=== | ===Setting Up Buttons=== | ||
Line 51: | Line 67: | ||
</ | </ | ||
If button " | If button " | ||
+ | |||
+ | Alternatively, | ||
==Randomizing Your Deck== | ==Randomizing Your Deck== |