title: Genereic LinkedStack/ Towers of Hanoi (non-recursive)
body: <p>The Assignment fro my data structures class is. Using the generic <code>LinkedStack</code> and <code>Node</code> classes provided, as well as the provided <code>TowersJob</code> class, solve the <em>Towers of Hanoi</em> problem non-recursively (write the <code>trn()</code> method in the file <code>TowersNonRecursive</code> by using a stack of <code>TowersJobs</code>). </p>
  
  <p>Test it on enough inputs (and verify your results with the “mystery” class) to be sure you have it working.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class TowersNonRecursive
  {
      public static void tnr(int n, String left, String middle, String right)
      {
          // WRITE THIS METHOD--NO RECURSION, USE A STACK OF TOWERSJOBS (USE THE GENERIC STACK)
          int start = 1, aux =3, end  =2;
          LinkedStack &lt;T&gt;t = new LinkedStack&lt;T&gt;();
          TowersJob tj = new TowersJob(n, left, middle, right);
          t.push(tj);
      }
      public static void main(String[] args) 
      {
          Scanner kbd = new Scanner(System.in);
          int n;
          String left, middle, right;
  
          System.out.print("Enter n:  ");
          n = kbd.nextInt();
          kbd.nextLine();
          System.out.print("Enter String 'left':  ");
          left = kbd.nextLine();
          System.out.print("Enter String 'middle':  ");
          middle = kbd.nextLine();
          System.out.print("Enter String 'right':  ");
          right = kbd.nextLine();
          System.out.println();
  
          tnr(n, left, middle, right);
  
      } 
  }
  </code></pre>
  
  <p>My question would be how do I create a stack of <code>TowerJobs</code> in the <code>trn()</code> method</p>
  
  <p>here are the other classes </p>
  
  <pre><code>public class LinkedStack&lt;T&gt;
  {
      private Node&lt;T&gt; top;
  
      public LinkedStack()
      {
          top = null;
      }
  
      public boolean isEmpty()
      {
          if (top == null)
              return true;
          else
              return false;
      }
  
      public T peek()
      {
          if (isEmpty())
              throw new RuntimeException("Peek attempted on empty stack");
          else
              return top.data;
      }
  
      public void push(T m)
      {
          Node&lt;T&gt; temp; 
          temp = new Node&lt;T&gt;();
          temp.data = m;
  
          temp.next = top;
          top = temp;
      }
  
      public T pop()
      {
          if (isEmpty())
              throw new RuntimeException("Pop attempted on empty stack");
          else
          {
              T temp = top.data;
              top = top.next;
              return temp;
  
  
          }
      }
  
  }
  
  
  
  public class Node&lt;T&gt;
  {
      public T data;
      public Node next;
  
  }
  
  public class TowersJob
  {
      public int n;
      public String left;
      public String middle;
      public String right;
  
      public TowersJob (int n, String left, String middle, String right)
      {
          this.n = n;
          this.left = left;
          this.middle = middle;
          this.right = right;
      }
  
      public String toString()
      {
          String t = "TowersJob: n = " + n;
          t = t + ", left = " + left; 
          t = t + ", middle = " + middle; 
          t = t + ", right = " + right; 
          return t;
      }
  
  }
  </code></pre>
  
  <p>Im totally lost on this assignment. My first issue would be initializing and creating the Stack of TowersJob in the first place. </p>