























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A way to bundle different types of information in C++ – like creating a custom data structure. Definition. Page 10. The GridLocation struct. ○ A pre-defined ...
Typology: Summaries
1 / 63
This page cannot be seen from the preview
Don't miss anything!
vectors + grids
stacks + queues
sets + maps
Object-Oriented Programming
arrays
dynamic memory management
linked data structures
algorithmic testing analysis
recursive problem-solving
C++ basics
Diagnostic
real-world algorithms
Core Tools
User/client Implementation
Object-Oriented Programming
arrays
dynamic memory management
linked data structures
algorithmic testing analysis
recursive problem-solving
C++ basics
Diagnostic
real-world algorithms
Core Tools
Implementation
vectors + grids
stacks + queues
sets + maps
User/client
Today’s
question
Review
(grids and queues and stacks, oh my!)
● A 2D array, defined with a particular width and height
● Useful for spreadsheets, game boards, etc.
● Three ways to declare a grid ○ Grid
● We could use a combination of Vectors to simulate a 2D matrix, but a Grid is easier!
● A pre-defined struct in the Stanford C++ libraries that makes it more convenient to store Grid locations
● To declare a struct, you can either assign each of its members separately or assign it when it’s created:
GridLocation origin = {0, 0}; GridLocation origin; origin.row = 0; origin.col = 0;
struct GridLocation { int row; int col; }
● Like a real queue/line!
● F irst person I n is the F irst person O ut (FIFO) ○ When you remove (dequeue) people from the queue, you remove them from the front of the line.
● Last person in is the last person served ○ When you insert (enqueue) people into a queue, you insert them at the back (the end of the line).
Types:
● Vectors (1D) ● Grids (2D)
Traits:
● Easily able to search through all elements ● Can use the indices as a way of structuring the data
Types:
● Queues (FIFO) ● Stacks (LIFO)
Traits:
● Constrains the way you can insert and access data ● More efficient for solving specific LIFO/FIFO problems
Activity:
towersOfHanoi()
● Rules: ○ Can only move one disk at a time ○ You cannot place a larger disk on top of a smaller disk
Discuss : How would
you solve this problem?
[breakout rooms]
(1) Move disk 1 to destination (2) Move disk 2 to auxiliary (3) Move disk 1 to auxiliary (4) Move disk 3 to destination
(5) Move disk 1 to source (6) Move disk 2 to destination (7) Move disk 1 to destination
Code the solution for
three disks!
[breakout rooms]