Linked Lists Flashcards

1
Q

How are linked list items structured?

A

Contains a value and a pointer to the next item in the list

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

What variables are needed for a linked list class?

A
  • Head: Points to the start of the linked list
  • Counter: How many items are in the list
  • maxSize: Limits the size of the linked list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Benefits of linked lists compared to arrays

A
  • Size is only limited by the system’s memory
  • Adding and removing data is much easier
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to addToHead() in a linked list?

A
  1. Create a new item
  2. Assign the pointer of the new item to the head
  3. Assign the head pointer to the new item
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to addToTail() in a linked list?

A
  1. Create a new item
  2. Assign the last item’s pointer to the new item
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to use addItemAt() to add an item in between the 4th and 5th element in a linked list?

A
  1. Create a new item
  2. Assign the pointer of the new item to the 5th element
  3. Assign the pointer of the 4th element to the new element
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to use removeItemAt() to remove the 7th item in a list?

A
  1. Assign the 6th item’s pointer to the 8th item
  2. The garbage collector will delete the 7th item as it’s been dereferenced
How well did you know this?
1
Not at all
2
3
4
5
Perfectly