Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package datastructures.graph;

import java.net.CookieManager;
import datastructures.linkedlist.Node;

import datastructures.graph.Edge;
import datastructures.graph.Vertex;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

public class Graph<T extends Comparable<? super T>> implements Comparable<Graph<T>> {

Expand All @@ -15,8 +20,12 @@ public Graph(int numberOfVertices) {

public Vertex<T> addVertex(T value) // addNode()
{
// TODO: implement me
return null;
Vertex<T> newVertex = new Vertex<>(value);
if(adjacencyLists.get(newVertex) == null){
adjacencyLists.put(newVertex, null);
numberOfVertices ++;
}
return newVertex;
}

public void addEdge(Vertex<T> start, Vertex<T> destination)
Expand All @@ -26,20 +35,37 @@ public void addEdge(Vertex<T> start, Vertex<T> destination)

public void addEdge(Vertex<T> start, Vertex<T> destination, int weight)
{
// TODO: implement me
Edge<T> newEdge = new Edge<>(destination, weight);
if(adjacencyLists.get(start) == null){
LinkedList<Edge<T>> newLinkedList= new LinkedList<>();
newLinkedList.add(newEdge);
adjacencyLists.put(start, newLinkedList);
}else {
LinkedList<Edge<T>> existingLinkedList = adjacencyLists.get(start);
existingLinkedList.add(newEdge);
adjacencyLists.put(start, existingLinkedList);
}
}

public LinkedList<Vertex<T>> getVertices() // getNodes()
{
// TODO: implement me
return null;
LinkedList<Vertex<T>> list = new LinkedList<>();
for (Vertex<T> vertex : adjacencyLists.keySet()){
list.add(vertex);
}
return list;
}

public LinkedList<Edge<T>> getNeighbors(Vertex<T> vertex)
{
// TODO: implement me
return null;
}
// public LinkedList<Edge<T>> getNeighbors(Vertex<T> vertex)
// {
// LinkedList<Edge<T>> list = new LinkedList<>();
// LinkedList<Edge<T>> edgeLinkedList = adjacencyLists.get(vertex);
// if(edgeLinkedList !=null){
// Node current;
// current = edgeLinkedList.
// }
// return list;
// }



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package datastructures.trees;

public class FizzBuzzTree {

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Node (T value) {
this.right = null;
}

// allows for constructing the trees easier in tests,
// allows for constructing the trees easier in test,
// since this allows for adding in the right and the left node.
public Node(T value, Node<T> left, Node<T> right) {
this.value = value;
Expand Down