Java

0.0(0)
studied byStudied by 2 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/37

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

38 Terms

1
New cards

What is a stack?

Data structure that removes items in reverse of the order in which they were inserted (Last in, First out → last item inserted will be the next to be removed)

2
New cards

Can stacks be implemented as linked lists?

Yes

3
New cards
4
New cards

How do you create a Stack object?

Stack s = new Stack();

5
New cards

What are the two methods of stacks?

·         push – adds item to the collection s.push(“A“)

·         pop – remove the most recently added item String item1 = s.pop()

6
New cards

How do you implement a Stack as a Linked list?

You have to create a node

7
New cards

What happens to the method when implementing a Stack as a Linked list

·         Push replaces add to start of list

·         Pop becomes remove from start of list

8
New cards

What is a queue?

A data structure that removes items in the same order in which they were inserted (First in, First out)

9
New cards

What are the methods for queues?

·         Enqueue – adds an item to a collection q.enqueue(“A”);

·         Dequeue – removes the item that has been in the queue the longest String item1 = q.dequeue;

10
New cards

How do you create a queue?

Queue q = new Queue();

11
New cards

What are the requirements of implementing a queue as a linked list?

·         Requires some changes to keep track of the end of the list

·         Must store a front and back node instead of just head

12
New cards

Can you implement queues as ArrayList?

Yes

13
New cards

Can you implement Stack as an ArrayList?

Yes

14
New cards

What is the benefit for having a doubly linked list?

A doubly linked list allows movement in both directions – has reference to next and previous node

<p><span style="font-family: &quot;Times New Roman&quot;; line-height: normal; font-size: 7pt;"><span> </span></span>A <strong>doubly linked list </strong>allows movement in both directions – has reference to next and previous node</p>
15
New cards

What does the .equals() compare two linked list?

Checks if they have the same node [may be dependent or independent of order]

16
New cards

How to create a deep copy for linked list?

To create a deep copy, you must traverse a linked list and create a (deep) copy of each node

17
New cards

What is an Iterator?

It is an object that enables object to iterator over their elements

18
New cards

How is iterators usually implemented?

Usually implemented as a public inner class

19
New cards

How to create an Iterator?

LinkedList.ListIterator i = list.iterator();

20
New cards

What does the .iterator() method return?

Iterator method returns an iterator

21
New cards

What are the two variables the Iterator uses?

Previous and position (Node type)

22
New cards

Example of how Iterator is implemented

knowt flashcard image
23
New cards

What does the reset method of an Iterator do?

Restart: Resets the iterator to the beginning of the list

24
New cards

What does the hasNext method of an Iterator do?

hasNext: Determines if there is another data item on the list

25
New cards

What does the next method of an Iterator do?

next: Produces next data item, moves iterator one position forward

26
New cards

What does the peek method of an Iterator do?

peek: Produces next data item, without moving iterator forward

27
New cards

What does the addHere method of an Iterator do?

addHere: Add a node at the current position in the linked list

28
New cards

What does the delete method of an Iterator do?

delete: Remove the current node

29
New cards

What does the changeHere method of an Iterator do?

changeHere: Modify the current node

30
New cards

With an iterator - how do you read each element?

i.restart();
while (i.hasNext())
	System.out.println(i.next());

31
New cards

How do you create a generic linked list?

knowt flashcard image
32
New cards

How do you add node in linked list

knowt flashcard image
33
New cards

How do you delete a node (linked list)

knowt flashcard image
34
New cards

How to peek at a node (linked list)

knowt flashcard image
35
New cards

How do you increment in a linked list

knowt flashcard image
36
New cards

What are pros with linked list compared to array?

knowt flashcard image
37
New cards

What are cons with linked list compared to array?

knowt flashcard image
38
New cards