Week 8 Flashcards
What are the two options of data structure design?
No meta-data, so the reference to the structure is just an element of the list itself.
Keep meta-data, so the reference to the structure is a struct of its own with a pointer to the actual data structure as part of that meta-data.
How do we make a data structure design private?
By default, if code can see the data type then it can look at it and change your data structure.
Some libraries only give you a generic pointer (void *) to the data type so that you can’t mess with the content.
List iterator: We may want someone to traverse a data structure without knowing the internals of the structure. What are our options?
Create a function that we call repeatedly for information to iterate over the list.
Let the user help to keep track of where we are in the list
Track the progress in the list on our own.
You can typically just iterate over one list at a time.
List Iterator: What is our second option for secure data structure internal traversal?
Let the list code call a specific function for each list item.
Use a given name for a function to call. (NOT FLEXIBLE)
Pass the function to call as a parameter (GOOD TO KNOW
What does strtok do?
Keeps the context in the function, destroys the string
What does strtok_r do?
Returns the context to the user, destroys the string
What function uses pointers to pointers?
strtok_r
The functions needs to change the value of the pointer, so the pointer is passed by reference.
What happens if we increment a pointer?
We end up pointing to the next array element.
When processing a string character-to-character, it’s not uncommon to use:…
An incrementing pointer