Pairs & Tuples
Group multiple values without custom structs. Learn pairs for coordinates and tuples for returns.
Lessons
1. Intro
Section Overview
2. What is a Pair?
Basic concept
3. Creating Pairs
Construction methods
4. Accessing Elements
Reading values
5. Quiz: Pair Access
Knowledge check
6. Comparing Pairs
How operators work
7. Pairs in Vectors
Storing multiple pairs
8. Quiz: Two-value container
Two-value container
9. Sorting Pairs
Automatic ordering
10. Quiz: Sorting Pairs
Knowledge check
11. Pairs with Maps
Key-value pairs
12. What is a Tuple?
Beyond two elements
13. Quiz: Two-value container
Two-value container
14. Creating Tuples
Construction syntax
15. Quiz: Tuple Creation
Knowledge check
16. Accessing Tuple Elements
Compile-time indexing
17. Structured Bindings
Automatic extraction
18. Tuple Comparison
Ordering rules
19. Quiz: Tuple Comparison
Knowledge check
20. Tie Function
Assign to existing variables
21. Pair vs Tuple vs Struct
Choosing the right tool
22. Quiz: Two-value container
Two-value container
23. Returning Multiple Values
Common pattern
24. Quiz: Return Values
Knowledge check
25. Coordinates and Points
Geometric applications
26. Graph Edges
Representing connections
27. Priority Queue with Pairs
Storing priorities
28. Quiz: Use Cases
Knowledge check
29. Map Iteration Patterns
Clean map traversal
30. Nested Pairs
When to stop
31. Quiz: Two-value container
Two-value container
32. Const Correctness
Avoiding copies
33. Quiz: References
Knowledge check
34. Swap and Assignment
Modifying pairs
35. Type Deduction Gotchas
Common mistakes
36. Quiz: Two-value container
Two-value container
37. Practice: Coordinate Sorting
Exercise
38. Practice: Map Statistics
Exercise
39. Quiz: Key-value storage
Key-value storage
40. Practice: Multi-Value Return
Exercise
41. Problem - Arrival of the General
Rearranging soldiers
42. General - The Pattern
Paired information
43. General - Algorithm
Breaking it down
44. Quiz: Two-value container
Two-value container
45. General - Implementation
Complete solution
46. Lessons from General
summary
47. Problem - George and Accommodation
Room availability
48. George - The Pattern
Simple filtering
49. George - Algorithm
Breaking it down
50. Quiz: Two-value container
Two-value container
51. George - Implementation
Complete solution
52. Lessons from George
summary
53. Section Recap
What we learned