Linked data structures - ch15 Flashcards

1
Q

linked data structure

A

consists of capsules of data known as nodes that are connected via links

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

link

A

references

  • memory address and is stored in a variable of a class type
  • link is an instance variable of the node class type itself
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

nodes

A

objects of the node class

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

data in a node is stored as,,,

A

stored via instance variables

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

linked list

A

consist of single chain of nodes each connected to the next via a link - first node: head node, last node: end marker

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

how to traverse through a linked list

A

while (position != null) { count++ /count is an int initialized to 0/; position = position.getLink( ); return count; }

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

getLink( )

A
returns an instance of a class - someone can change the class? Privacy leak -- to fix this: make the node class private and inside linked list class -create node class
All you need for a node class- (you don’t need accessor or mutator methods)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

indicating the end of the linked list

A

link instance variable equal to null… == not .equals

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

adding a node

A

adds node to the start of the linked list - the new node is now the head node

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

deleting a head node

A

deleteHeadNode removes the first node from the linked list

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

what happens when using deleteHeadNode()

A

leaves the head var pointing to the old second node
the deletes one will automatically be collected and its memory recycled along with any other nodes that are no longer accessible - automatic garbage collection

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

node inner classes

A

have the node class be inner classes of the linked list class

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

generic linked list

A

can hold objects of any class type - including types that contains multiple instance variables

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

the copyOf method

A

The private helping method copyOf takes an argument that is a reference to a head node of a linked list, and returns a reference to the head node of a copy of that list

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

shallows and deep copy constructors, publicly cloneable , clone method, equals method

A

do examples - see notes

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

what is an iterator

A

any object that enables a list to be traversed

a linked list can be created with an iterator inner class

17
Q

what are the basic methods used by an iterator

A

restart
next
hasNext

18
Q

what is an iterator usually used for?

A

adding and deleting nodes

19
Q

how does deleting a node at a certain position work

A

bypassing that particular node and change the node - does the node disappear - not immediately, it then becomes garbage

20
Q

explicit memory management

A

when the programmer has to keep track of the deleted nodes and explicitly return their memory for recycling

21
Q

adding a node to a specific position

A
previous will point to the node before the insertion point, and position will point to the node after the insertion point Node temp = new Node(newData,position);
previous.link = temp;
22
Q

how does it work when adding a node to a certain position

A

create a node with the link the the current position node
makes the previous node link to the reference of the new node
it now flows

23
Q

what is a doubly linked list

A

each node knows what the next and previous nodes are - 2 way node chain

24
Q

adding, deleting and inserting a node to a doubly linked list

A

google simpler thing

25
Q

stack data structure

A

Removes items in the reverse order - Last in first out LIFO
Implementing linked list without the iterator - basically implementing a stack
Inserting a node - push
Pop - deletes the head node
Can create own stack using an array

26
Q

queue data structure

A

FIFO - first in first out
Can use a linked list - we are inserting at the tail - we need to be able to add to the end of the queue and then we remove from the head
Dequeue - add to both ends of the queue
Queue in Java is actually an interface that can be implemented
ArrayDequeue class - implements your queue as an array

27
Q

what is dequeue

A

Dequeue - add to both ends of the queue