AuK/Durchläufe durch Graphen SS12

Aus ProgrammingWiki

Wiki-Quelltext dieser Seite.

<language>Java</language>
=Java-Test=

<pre>
class StackX
   {
   private final int SIZE = 20;
   private int[] st;
   private int top;

   public StackX()           // constructor
      {
      st = new int[SIZE];    // make array
      top = -1;
      }

   public void push(int j)   // put item on stack
      { st[++top] = j; }

   public int pop()          // take item off stack
      { return st[top--]; }

   public int peek()         // peek at top of stack
      { return st[top]; }

   public boolean isEmpty()  // true if nothing on stack
      { return (top == -1); }

   }
</pre>

<code id="4f8d8fe214252">
public Object Stack ()
{
   int size = 10;
   int[] st = new int[size];
   int top = -1;

   public void push(int j)
      {st[++top] = j;}

   public int pop()
      {return st[top--];}

   public int peek()
      {return st[top];}

   public boolean isEmpty()
      {return (top == -1);}
   
   return this;

}


public Object Vertex (char label)
{
   char label = label;
   boolean wasVisited = false;

   return this;
}

</code>

<run id="4f8d8fe2142bd">
Stack01 = Stack();
Stack01.push(1);
Stack01.push(2);
Stack01.push(4);
Stack01.push(5);
Stack01.push(3);

VertexA = Vertex('A');
System.out.println(VertexA.wasVisited + "\n" +
VertexA.label);

</run>