Vectors vs. Arrays (i.e. why Vectors are better)
Pros of Vectors over C-style arrays:
Vectors can be larger (hold more elements), can grow over time, keep track of their size, don't decay to a pointer if you sneeze on them, initialize all of their elements, do bounds-checking with at(), always work with range-based for loops, and vectors can have variable sizes.
Pros of C-style arrays over Vectors:
1) Slightly faster to make one in terms of running time
2) Slightly faster to make one in terms of typing the code
The big difference is, of course, the bounds-checking (which means making sure you don't go off either edge of the array or vector). So many people use arrays and so many of them don't bounds-check properly. The website today I just randomly found and it would do really, really bad things to memory. Friends don't let friends use arrays.
If you absolutely have to have an array for speed reasons, in general you should be using a C++ array instead, since it is just... better. But for this class, you should use Vectors 99% of the time, and of the remaining 1%, 99% of that time you should use C++ arrays instead of C-style arrays.
We finished by showing how to write a sorting algorithm that takes in a vector and sorts it in place using a very inefficient method called bubble sort. 99% of the time, you should never use any of these O(N^2) sorting algorithms, and just use the standard library's sort() routine instead.
Other Videos By Bill Kerney
2021-09-29 | Making a Castle with the Procedural Spline Walls System |
2021-09-28 | Making an AI Opponent Part I |
2021-09-28 | Graph Theory I |
2021-09-27 | 2D Vectors and Arrays |
2021-09-27 | Scratch Part II |
2021-09-25 | Auto + Growing Vectors + Nonblocking I/O |
2021-09-24 | Introduction to Scratch |
2021-09-23 | Niagara Part II |
2021-09-23 | Landscape + Foliage, Hitscan Weapons, Niagara Particle Effects |
2021-09-23 | Syllogisms |
2021-09-23 | Vectors vs. Arrays (i.e. why Vectors are better) |
2021-09-22 | Ethics in Autonomous Vehicles |
2021-09-21 | Karnaugh Maps, Simplifying If Statements |
2021-09-21 | Destructible Meshes - Blueprint Interactions |
2021-09-20 | Ethical Systems II - Is/Ought + Virtue Ethics |
2021-09-18 | Digital Logic II |
2021-09-17 | Making Video Games Interactive + Blueprints Coding |
2021-09-17 | Doubly Nested Loops + Chars + Strings |
2021-09-17 | Ethical Theories I |
2021-09-17 | Introducing Colorslib |
2021-09-16 | Voronoi Relaxation / Lloyd's Algorithm |