Learn how to use a custom queue in Swift and how it can be used to represent various situations, including a line of people waiting for a specific event.
- [Instructor] Now that the blueprint is done,…and we know what a queue contains and how we can interact…with it, let's create our first queue in code.…In this case, we'll represent three people standing in line…where Peggy is the first in line,…Larry is the second and Serena is the third.…Then, we'll use a few functions from our blueprint.…First, we'll print out whoever's the first in line…with the peek function.…So we'll write myQueue.peek, then we'll see if it's…still the same when we peek again.…
Then we'll dequeue from our queue, so remove an item…from our queue and then we'll see how the peek…or how the first item of the queue has changed.…Again, we'll need to unwrap these values,…unwrap these optionals so that way we can get the true value…of what they contain if the peek is null,…then we would get an error here.…Let's go ahead and run this code.…The first thing we do is enqueue Peggy…and then Larry and then Serena.…So when we peek, we should see Peggy at the front…of our queue, which we do right here.…
- 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?
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.