# Kahns Algorithm implementation using java

Complete program to Kahns Algorithm

```package com.thealgorithms.datastructures.graphs;

import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.Queue;

/**
* An algorithm that sorts a graph in toplogical order.
*/
/**
* A class that represents the adjaceny list of a graph
*/

}

/**
*
* @param from , the vertex the edge is from
* @param to, the vertex the edge is going to
*/
void addEdge(E from, E to) {
try {
} catch (Exception E) {
}
}
}

/**
* @param v, A vertex in a graph
* @return returns an ArrayList of all the adjacents of vertex v
*/
}

/**
* @return returns a set of all vertices in the graph
*/
Set<E> getVertices() {
}

/**
*/
void printGraph() {
for (E vertex : adj.keySet()) {
System.out.print(vertex + " : ");
}
System.out.println();
}
}
}

class TopologicalSort<E extends Comparable<E>> {

Map<E, Integer> inDegree;

this.graph = graph;
}

/**
* Calculates the in degree of all vertices
*/
void calculateInDegree() {
inDegree = new HashMap<>();
for (E vertex : graph.getVertices()) {
if (!inDegree.containsKey(vertex)) {
inDegree.put(vertex, 0);
}
try {
} catch (Exception e) {
}
}
}
}

/**
* Returns an ArrayList with vertices arranged in topological order
*/
ArrayList<E> topSortOrder() {
calculateInDegree();

for (E vertex : inDegree.keySet()) {
if (inDegree.get(vertex) == 0) {
}
}

while (!q.isEmpty()) {
E current = q.poll();
}
}
}

}
}

/**
* A driver class that sorts a given graph in topological order.
*/
public class KahnsAlgorithm {

public static void main(String[] args) {

//Graph definition and initialization