public void prim(int startNode) {
        Node[] S = new Node[size];  //vertices in the spanning tree
        PriorityQueue<Node> V_S = new PriorityQueue();  //remaining vertices
        Node[] p = new Node[size];  //source vertex for edge

        Node[] spanningTree = new Node[size];
        initNodes(spanningTree);

        /*Initialize S with start vertex, s, and V_S with the remaining vertices*/
        int S_tail = 0;
        Node start = graph[startNode];
        S[S_tail] = spanningTree[start.index];    //Initialize S with start vertex
        start.d = 0;
        p[start.index] = spanningTree[start.index];
        S_tail++;

        /*Initialize V_S with the remaining vertices*/
        int currentNode = startNode;
        currentNode = (currentNode + 1) % size;
        while (currentNode != startNode) {
            Node v = graph[currentNode];

            /*for all v in V_S (line 2 - 6)*/
            int vIndex = v.index;   //find index in matrix
            p[vIndex] = S[0];
            if (start.connections[vIndex] != null) {   //if there is an edge (s,v)
                v.d = start.connections[vIndex].weight;
            }
            V_S.add(v);

            currentNode = (currentNode + 1) % size; //increment looping index
        }
        /*main loop*/
        while (!V_S.isEmpty()) {
            Node uTemp = V_S.remove();  //remove smallest d item
            Node u = spanningTree[uTemp.index];
            S[S_tail] = u;
            S_tail++;

            try {
                p[u.index].setConnection(u, uTemp.connections[p[u.index].index].weight, u.index);
            } catch (NullPointerException e) {
            }

            PriorityQueue<Node> V_Stemp = new PriorityQueue();  //need temporary Queue to store updated values
            /*for all v in V_S*/
            while (!V_S.isEmpty()) {
                Node vTemp = V_S.remove();
                Node v = spanningTree[vTemp.index];
                Edge u_v = uTemp.connections[v.index];
                if (u_v != null && u_v.weight < vTemp.d) {
                    vTemp.d = u_v.weight;
                    p[v.index] = u;
                }
                V_Stemp.add(vTemp);
            }
            V_S = V_Stemp;
        }
        /*traverse tree to find distances*/
        System.out.println("Primm's minimum spanning tree");
        primmTraversal(S[0], 0, startNode);
    }