Week 8 Flashcards

1
Q

What are the two options of data structure design?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do we make a data structure design private?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

List iterator: We may want someone to traverse a data structure without knowing the internals of the structure. What are our options?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

List Iterator: What is our second option for secure data structure internal traversal?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does strtok do?

A

Keeps the context in the function, destroys the string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does strtok_r do?

A

Returns the context to the user, destroys the string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What function uses pointers to pointers?

A

strtok_r

The functions needs to change the value of the pointer, so the pointer is passed by reference.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What happens if we increment a pointer?

A

We end up pointing to the next array element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When processing a string character-to-character, it’s not uncommon to use:…

A

An incrementing pointer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly