Algorithm Pseudocodes Flashcards

1
Q

Singly Linked List Node Class

A

public class SinglyLinkedList{private static Class Node{private E element;private Node next;public Node (E e, Node n){element = e;next = n;}public E getElement(){return element;}public Node getNext(){return next;}public void setNext(Node n){next = n;}}}

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

Singly Linked List removeFirst()

A

public E removeFirst(){if(isEmpty()) return null;E answer = head.getElement();head = head.getNext();size–;if (size == 0)tail = null;return answer;}

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

Doubly Linked List addInBetween() method

A

public void addInBetween(String data, Node node){ Node newNode = new Node(data, node.next, node); node.setNext(newNode); newNode.getNext().setPrev(newNode); }

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

Doubly Linked List removeFirst() method

A

public Node removeFirst(){ Node node = head.getNext(); head.setNext(node.getNext()); node.getNext().setPrev(node.getPrev()); size–; return node; }

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

Doubly Linked List removeLast() method

A

public Node removeLast(){ Node node = tail.getPrev(); tail.setPrev(node.getPrev()); node.getPrev().setNext(node.getNext()); size–; return node; }

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

Doubly Linked List toArrayFromFirst() method

A

public String[] toArrayFromFirst(){ String[] nodeArray = new String[size]; Node position = head.getNext(); for(int i = 0; i < size; i++){ nodeArray[i] = position.getData(); position = position.getNext(); } return nodeArray; }

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

Doubly Linked List toArrayFromLast() method

A

public String[] toArrayFromLast(){ String[] nodeArray = new String[size]; Node position = tail.getPrev(); for (int i = 0; i < size; i++){ nodeArray[i] = position.getData(); position = position.getPrev(); } return nodeArray; }

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

Doubly Linked List deepClone() method

A

public DoublyLinkedList deepClone(){ DoublyLinkedList List = new DoublyLinkedList(); Node position = head.getNext(); for(int i = 0; i < size(); i++){ List.addLast(position.getData()); position = position.getNext(); } return List;

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