Graph in Array aus Adjazenzlisten

vinc_21

Neues Mitglied
Guten morgen!
Wie das Thema schon sagt....Ich habe auch noch ein bisschen Zeit. Über Hinweise würde ich mich freuen. Komme nicht weiter. Die toString Methode habe ich noch nicht begonnen. Soll aber auch nicht Thema dieses Posts sein.


Java:
import java.util.Arrays;
import java.util.LinkedList;

public class GraphAdjacencyList implements GraphInterface {

    // AdjacencyList ist eine Kindklasse von LinkedList<Edge>
    // und kann als solche betrachtet werden
    // (notwendig, da Arrays von generischen Datentypen in Java nicht erlaubt sind)
    private AdjacencyList[] edges;
   
    private class Edge {
        public int numberOfNeighbour;
        public int weight;
       
        public Edge(int numberOfNeighbour, int weight) {
            this.numberOfNeighbour = numberOfNeighbour;
            this.weight = weight;
        }
    }
   
    private class AdjacencyList extends LinkedList<Edge> {}
   
    // Hilfsmethode prueft, ob in Adjazenzliste von Knoten "from" eine Kante zu Knoten "to" existiert
    private Edge getEdge(int from, int to) {
        Edge temp = null;
        for (Edge k : edges[from]) {
            if (k.numberOfNeighbour == to) {
                temp = k;
            }
        }
        return temp;
    }

    // parametrisierter Konstruktor initialisiert einen neuen Graphen fuer eine feste Anzahl von Knoten
    public GraphAdjacencyList (int nVertices) {
        AdjacencyList[] egdes=new AdjacencyList[nVertices];
        for(int i=0;i<nVertices;i++){
            edges[i]=new AdjacencyList();
        }
           
    }

    // fuegt eine Kante hinzu, welche die Knoten from und to mit dem Gewicht weight verbindet
    public void addEdge(int from, int to, int weight) {
        Edge testa=edges[from].getEdge(from,to);
        Edge testb=edges[to].getEdge(to,from);
        if(test=null){
        Edge a=new Edge(to,weight);
        Edge b=new Edge(from,weight);
        edges[from].add(a);
        edges[to].add(b);
       
    }else{
        testa.weight=weight;
        testb.weight=weight;
       
       
    }
    }
    // gibt die Anzahl der Nachbarn des Knotens vertex zurueck
    public int getDegree(int vertex){
        return edges[vertex].size();
    }

    // gibt ein Array mit den Indizes der Nachbarknoten von vertex zurueck
    public int[] getNeighbours(int vertex) {
        int[] ndex=new int[edges[vertex].size()];
        for(int i=0;i<edges[vertex].size();i++){
        index[i]=edges[vertex].get(i).numberOfNeighbour;
        }
        return ndex;
       
        }

    // gibt die Anzahl der Knoten im Graphen zurueck
    public int getNumberOfVertices() {
        return edges.lenght;// Todo
    }

    // gibt das Gewicht der Kante zwischen Knoten from und to zurueck
    public int getWeight(int from, int to) {
        Edge test=edges[from].getEdge(from,to);
        if(test!=null){
            return test.weight;
        }else{
            return 0;
        }
    }

    // entfernt die Kante, die Knoten from und to verbindet
    public void removeEdge(int from, int to) {
        edges[from].remove(edges[from].get(from,to));
        edges[to].remove(edges[to].get(to,from));
     
           
        }
   

    // visualiert den Graphen
    public String toString(){
        // Todo
    }
}



Meine Fehlermeldung:

8 errors

C:\Users\ne\Graph>javac GraphAdjacencyList.java
GraphAdjacencyList.java:45: error: cannot find symbol
Edge testa=edges[from].getEdge(from,to);
^
symbol: method getEdge(int,int)
location: class GraphAdjacencyList.AdjacencyList
GraphAdjacencyList.java:46: error: cannot find symbol
Edge testb=edges[to].getEdge(to,from);
^
symbol: method getEdge(int,int)
location: class GraphAdjacencyList.AdjacencyList
GraphAdjacencyList.java:47: error: cannot find symbol
if(test=null){
^
symbol: variable test
location: class GraphAdjacencyList
GraphAdjacencyList.java:69: error: cannot find symbol
index=edges[vertex].get(i).numberOfNeighbour;
^
symbol: variable index
location: class GraphAdjacencyList
GraphAdjacencyList.java:77: error: cannot find symbol
return edges.lenght;// Todo
^
symbol: variable lenght
location: variable edges of type GraphAdjacencyList.AdjacencyList[]
GraphAdjacencyList.java:82: error: cannot find symbol
Edge test=edges[from].getEdge(from,to);
^
symbol: method getEdge(int,int)
location: class GraphAdjacencyList.AdjacencyList
GraphAdjacencyList.java:92: error: no suitable method found for get(int,int)
edges[from].remove(edges[from].get(from,to));
^
method List.get(int) is not applicable
(actual and formal argument lists differ in length)
method AbstractList.get(int) is not applicable
(actual and formal argument lists differ in length)
method AbstractSequentialList.get(int) is not applicable
(actual and formal argument lists differ in length)
method LinkedList.get(int) is not applicable
(actual and formal argument lists differ in length)
GraphAdjacencyList.java:93: error: no suitable method found for get(int,int)
edges[to].remove(edges[to].get(to,from));
^
method List.get(int) is not applicable
(actual and formal argument lists differ in length)
method AbstractList.get(int) is not applicable
(actual and formal argument lists differ in length)
method AbstractSequentialList.get(int) is not applicable
(actual and formal argument lists differ in length)
method LinkedList.get(int) is not applicable
(actual and formal argument lists differ in length)
8 errors
 

vinc_21

Neues Mitglied
Okay. habe gerade noch Schreibfehler gefunden.
Darüberhinaus ist mir gerade aufgefallen,dass getEdge gar keine Methode von AdjacencyList ist^^

Ich melde mich nochmal wenn ich neue Probleme habe. sorry^^
 

Neue Themen


Oben