Linked List Flashcards

1
Q

What is a linked list?

A

linked list diagram

ordered collection of data = node with data and reference to the next node;
order won’t change
head, node, data, reference to the next node, tail
Create 2 separate nodes and point one to next.

Images from Algorithms - linked lists doc

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

Coding exercise - linked lists.

A

Use new Node to set up node one and node 2

Use a constructor to set up class Node
class Node {

}

class LinkedList {

}
Why set to null instead of undefined?
undefined means the data hasn’t been set
null means it has been set to undefined

linkedList only knows about the first node = head, if you want info about other nodes, you have to crawl up the linked list

Use a constructor to create a class LinkedList and set the head to point to a node

Images from Algorithms - linked lists doc

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

Linked List’s InsertFirst

A

create a head
create a node
break link on head with the class
move new node to be first and link it to tail (stick it to the front) - meaning before the former head
link the class with the head (update the head reference)

Images from Algorithms - linked lists doc

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

sizing a list

A

Images from Algorithms - linked lists doc

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

linkList’s methods: getFirst, getLast, clear, removeFirst

A

getFirst{
return this.head
{

getLast{}
Images from Algorithms - linked lists doc

clear(){
This.head = null
}

removeFirst()

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

Remove last

A

Images from Algorithms - linked lists doc

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

Insert last

A

Images from Algorithms - linked lists doc

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