This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Collection; | |
import java.util.Comparator; | |
import java.util.EnumMap; | |
import java.util.HashMap; | |
import java.util.LinkedHashMap; | |
import java.util.Map; | |
import java.util.Set; | |
import java.util.TreeMap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayDeque; | |
import java.util.Arrays; | |
import java.util.Comparator; | |
import java.util.Deque; | |
import java.util.PriorityQueue; | |
import java.util.Queue; | |
public class JavaQueues { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.Comparator; | |
import java.util.HashSet; | |
import java.util.Set; | |
import java.util.SortedSet; | |
import java.util.TreeSet; | |
public class JavaSets { | |
public static void main(final String[] args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.LinkedList; | |
import java.util.List; | |
public class JavaLists { | |
public static void main(String[] args) { | |
//////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Queue { | |
constructor() { | |
this.queue = []; | |
} | |
// Allows us add items to the back of the array. | |
enqueue(item) { | |
this.queue.push(item); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Queue { | |
constructor() { | |
this.queue = []; | |
this.stack = []; | |
} | |
dequeue() { | |
if (this.stack.length === 0) { | |
while (this.queue.length > 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stack { | |
constructor() { | |
this.stack = []; | |
} | |
push(item) { | |
this.stack.push(item); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node { | |
constructor(data, next) { | |
this.data = data; | |
this.next = null; | |
} | |
} | |
const linkedList = new Node(5); | |
linkedList.next = new Node(10); | |
linkedList.next.next = new Node(15); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node { | |
constructor(data, prev = null, next = null) { | |
this.data = data; | |
this.prev = prev; | |
this.next = next; | |
} | |
} | |
const doubleLinkedList = new Node(0); | |
const secondItem = doubleLinkedList.next = new Node(1, doubleLinkedList); | |
const thirdItem = secondItem.next = new Node(2, secondItem); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node { | |
constructor(data) { | |
this.data = data; | |
this.left = null; | |
this.right = null; | |
} | |
} | |
class Tree { | |
constructor(data) { | |
const node = new Node(data); |
NewerOlder