Linked Lists Part II: More Push and Pop functions
Whenever working with pointers, there's a couple rules you should always follow:
1) Any time there is an arrow operator, ask yourself, "Am I confident that this pointer is not going to be null?" If you're not confident, then add a check, like this:
if (!ptr) die(); // or handle it however you want
!ptr is true when ptr is 0, aka, nullptr, aka NULL
2) Whenever you work with a linked list, always sketch it out on pen and paper, and see if any pointers need to be updated when nodes get added or deleted from the data structure.
3) Whenever working with classes, always think about your class invariants, the things that must always be true after one of your member functions returns. For linked lists, we can come up with a couple: "Head must always point at the front of the list, or NULL if the list is empty", "Tail must always point at the end of the list, or NULL if the list is empty", "SIZE must always have the current size of the list" and so forth. Every time you have a non-const method, you must super extra double check that none of the invariants can be violated by your code.
Other Videos By Bill Kerney
2022-02-25 | Midterm I Review Part II |
2022-02-24 | UE4 Water Plugin + Projectile Weapons |
2022-02-23 | UNCC's BRIDGES |
2022-02-23 | Midterm Review + Ethics of Autonomous Vehicles |
2022-02-22 | Week 7 - Voronoi 2: Lloyd's Algorithm + Edge Detection |
2022-02-16 | Lecture 42 - Lambda Functions, Pointer Loops, Function Pointers, Life |
2022-02-16 | The Housing Crisis |
2022-02-15 | Voronoi Regions |
2022-02-14 | Linked Lists III - Inserting and Deleting from the Middle |
2022-02-14 | Ethics (Part IV): Virtue Ethics |
2022-02-13 | Linked Lists Part II: More Push and Pop functions |
2022-02-11 | ACM Workshop: Intro to Python |
2022-02-11 | Ethics (Part III): Kantian Ethics, Natural Rights |
2022-02-10 | Importing a material into UE4 in 10 minutes |
2022-02-09 | Introduction to Linked Lists |
2022-02-09 | Facial Recognition and Ethics (Part II on Ethics) |
2022-02-08 | UE4 Niagara (+ a bit on Source Control) |
2022-02-07 | Advice on how to approach the RTX On project |
2022-02-07 | The Ethics of NFTs |
2022-02-04 | Bounding Volume Hierarchy |
2022-02-04 | Conditionals |