Learn how to use a custom stack in Swift as well as how you might approach it in other languages. Walk through an example of how you could represent a deck of cards in code.
- [Instructor] Using the example of card deck,…let's use the stack we just blueprinted…and implemented out in our code.…In this case, each item in our deck,…each item in our stack will represent a card…and each card will be represented with a string.…You could create a card class or a card struct…if you wanted to, but to keep things simple here,…we're just going to be using strings.…In our deck, the first thing we do is push on a couple…of items.…We push on a queen that's a heart,…a jack that's a spade, a nine that's a heart,…and a four that's a diamond.…
Then, we peek and see what's on top of our stack…and both of these cases will have a diamond that's a four.…Now you might be wondering why we had…these exclamation points here.…Essentially, what they do is they unwrap our optional value.…So they're unwrapping what's returned by this peek.…An optional is something that could have a value…or it could be null.…By unwrapping it, we reveal its true value.…If we go ahead and execute,…we'll see that it's the diamond four in both cases.…
- Data types: Booleans, numbers, strings, and more
- Multidimensional arrays
- Jagged arrays
- Search and sort arrays
- Linked lists
- Stacks and queues
- Hash functions and hash tables
- Trees and graphs
Skill Level Intermediate
Understand data structures1m 25s
1. Introduction to Data Structures
4. Stacks and Queues
5. Hash-Based Data Structures
6. Trees and Graphs
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.