Wednesday, 25 October 2023

Chapter 27 // Exercise 6, 7 - Principles & Practice Using C++

In this exercise I'm using Visual Studio 2022.

Chapter 27 // Exercise 6

Change the representation of Link and List from section 27.9 without changing the user interface provided by the functions. Allocate Links in an array of links and have the members first, last, pre, and suc be ints (indices into the array).

I honestly had no idea what he meant when I read this so I asked ChatGPT to explain it to me like I'm 5. It was very helpful and I realised that what he wanted us to do was kind of create a vector where you can traverse the list via an index and then access the data at that index.

I had a stab at it for a couple of hours but honestly, my head just wasn't in it. I cannot stand anything to do with linked lists, never mind linked lists in C. So I left it half finished. The code I linked above kind of works but it also kinda doesn't.

Chapter 27 // Exercise 7

What are the advantages and disadvantages of intrusive containers compared to C++ standard (non-intrusive) containers? Make a list of pros and cons.

Github: N/A

I won't write an entire essay but from what I've seen intrusive containers would've been very normal back when C ruled the land. They're extremely lightweight versions of C++ templated containers, only you don't get the flexibility/generic-ness of the templated container but you get better performance. 

I suppose they would be useful in embedded systems where you know exactly what you're working with and have specific memory constraints. 

No comments:

Post a Comment