Durchläufe durch Graphen SS12

Aus ProgrammingWiki
< AuK
Archivierte Version vom 2012-04-29T20:54:55+00:00. Aktuelle Version

Java-Test


  for(int i =0; i<=knotenanzahl; i++)
     for(int j=0; j<=knotenanzahl; j++)
        adjazenzMatrix[i][j] = 0;
  
  public void addEdge(int start, int end)
  {
     adjazenzMatrix[start][end] = 1;
     // adjazenzMatrix[end][start] = 1; //nur für ungerichtete Graphen!! 
  }
  public void addVertex(char lab)
  {
     knotenliste[knoten++] = Vertex(lab);
  }
  public void displayVertex(int v)
  {
     System.out.print(knotenliste[v].label);
  }
  public void dfs()
  {
     System.out.println("\nDFS-Durchlaufordnung:");
     knotenliste[0].bereitsBesucht=true;
     displayVertex(0);
     stacky.push(0);
     while (!stacky.istLeer())
     {
        int v = getAdjUnvisitedVertex(stacky.peek());
        if(v == -1) stacky.pop();
        else 
        {
           knotenliste[v].bereitsBesucht = true;
           displayVertex(v);
           stacky.push(v);
        }
     }
     for(int j=0; j<knoten j knotenliste false><pre>  public void bfs()
  {
     System.out.println("\nBFS-Durchlaufordnung:");</pre><pre>     knotenliste[0].bereitsBesucht = true;
     displayVertex(0);
     queuey.enqueue(0);</pre><pre>     while( !queuey.istLeer() )
     {
        int v = getAdjUnvisitedVertex( queuey.peek() );
        if(v == -1)
           queuey.dequeue();
        else
        {
           knotenliste[v].bereitsBesucht = true;
           displayVertex(v);
           queuey.enqueue(v);
        }
     }
     
     for(int j=0; j<knoten j knotenliste false><pre>  public int getAdjUnvisitedVertex(int v)
  {
     for(int j=0; j<knoten j if knotenliste return><pre>  public void zeigeAdjMatrix()
  {
     /*for(int col=0; col<max_verts col adjmat><pre>     for(int row=0; row<max_verts row adjmat system.out.println><pre>     for (int k = 0; k &lt; this.knotenanzahl; ++k) {
       for (int l = 0; l &lt; this.knotenanzahl; ++l) {
          System.out.print(this.adjazenzMatrix[k][l] + "\t");}
       System.out.println("");}
  }
  
  return this;</pre><p>}
</p><p><br></p>
</max_verts></pre></max_verts></pre></knoten></pre></knoten></pre></knoten>