title: Find perfect maze path, using Graph structure
body: <p>I have this classes and code that solve the maze, but i don't understand why solution is written this way... it doesn't even use the graph...</p>
  
  <p>Here is the GraphNode : <a href="http://pastebin.com/DMprKQAN" rel="nofollow">http://pastebin.com/DMprKQAN</a></p>
  
  <p>Here is the Graph : <a href="http://pastebin.com/ueCWqPww" rel="nofollow">http://pastebin.com/ueCWqPww</a></p>
  
  <p>Maze class:</p>
  
  <pre><code>public class Lavirint {
      Graph&lt;String&gt; g;
      int start_node; 
      int end_node;
  
      Hashtable&lt;String, Integer&gt; h;
  
      public Lavirint() {
          h = new Hashtable&lt;String, Integer&gt;();
          g= null;
      }
  
      void generateGraph(int rows, int columns, String[] in) {
  
          int num_nodes = 0;
          String key;
          for(int i=1; i&lt;rows-1; i++){
              for(int j=1; j&lt;columns-1; j++){
                  if(in[i].charAt(j)!='#'){
                      key = i+","+j;
                      h.put(key, num_nodes);
                          if(in[i].charAt(j)=='S')
                              start_node = num_nodes;
                              if(in[i].charAt(j)=='E')
                                  end_node = num_nodes;
                  num_nodes++;
                  }
              }
          }
  
          g = new Graph&lt;String&gt;(num_nodes);
          int x, y;
              // Generating neighbours matrix
          for(int i=1; i&lt;rows-1; i++){ 
              for(int j=1; j&lt;columns-1; j++){
                  if(in[i].charAt(j)!='#'){
                      if(in[i].charAt(j-1)!='#'){ 
                          x = h.get(i+","+j); y = h.get(i+","+(j-1));
                          g.addEdge(x, y);
                      }
                      if(in[i].charAt(j+1)!='#'){
                          x = h.get(i+","+j); y = h.get(i+","+(j+1));
                          g.addEdge(x, y);
                      }
                      if(in[i-1].charAt(j)!='#'){
                          x = h.get(i+","+j); y = h.get((i-1)+","+j);
                          g.addEdge(x, y);
                      }
                      if(in[i+1].charAt(j)!='#'){
                          x = h.get(i+","+j); y = h.get((i+1)+","+j);
                          g.addEdge(x, y);
                      }
                  }
              }
          }
      }
  
      void findPath() {
          boolean visited[] = new boolean[g.num_nodes];
          for (int i = 0; i &lt; g.num_nodes; i++)
              visited[i] = false;
          visited[start_node] = true;
          Stack&lt;Integer&gt; s = new Stack&lt;Integer&gt;();
          s.push(start_node);
          int pom,pom1;
          while (!s.isEmpty() &amp;&amp; s.peek()!=end_node) {
              pom = s.peek();
              pom1 = pom;
          for (int i = 0; i &lt; g.num_nodes; i++) {
              if(g.adjacent(pom,i)==1){
                  pom1 = i;
                  if(!visited[i])
                      break;
              }
          }
          if(!visited[pom1]){
              visited[pom1] = true;
              s.push(pom1);
          }
          else
              s.pop();
          }
          Stack&lt;Integer&gt; os = new Stack&lt;Integer&gt;();
          while(!s.isEmpty())
              os.push(s.pop());
          while(!os.isEmpty()) {
              String t=null;
              Iterator&lt;Entry&lt;String,Integer&gt;&gt; it=(h.entrySet()).iterator();
              int i=os.pop();
              while(it.hasNext()) {
                  Entry&lt;String, Integer&gt; entry=it.next();
                  if (entry.getValue()==i) {
                      System.out.println(entry.getKey());
                      break;
                  }
              }
  
          }
      }
  
      public static void main(String args[]) throws Exception {
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          Lavirint l = new Lavirint();
          String pom = br.readLine();
          String[] ppom = pom.split(",");
          int rows = Integer.parseInt(ppom[0]);
          int columns = Integer.parseInt(ppom[1]);
          String[] in = new String[rows];
  
          for (int i = 0; i &lt; rows; i++) 
              in[i] = br.readLine();
  
          l.generateGraph(rows, columns, in);
  
          l.findPath();
      }
  
  }
  </code></pre>
  
  <p>I don't understand why when the Graph is being generated GraphNode.info is empty and only Edges are marked, so because it is done, finding the path() has weird solution...
  All i wanna know is this is good or right approach and if i solve this maze using Char for info variable in GraphNode will be bad solution??</p>
  
  <p>Test Cases:</p>
  
  <p>1.</p>
  
  <pre><code>6,6
  ######
  #S# E#
  # # ##
  #   ##
  ######
  ######
  </code></pre>
  
  <p>Answer:</p>
  
  <pre><code>1,1
  2,1
  3,1
  3,2
  3,3
  2,3
  1,3
  1,4
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>8,8
  ########
  #  S####
  # ##   #
  #    # #
  ###### #
  #####  #
  #####E##
  ########
  </code></pre>
  
  <p>Answer:</p>
  
  <pre><code>1,3
  1,2
  1,1
  2,1
  3,1
  3,2
  3,3
  3,4
  2,4
  2,5
  2,6
  3,6
  4,6
  5,6
  5,5
  6,5
  </code></pre>