title: Stacks and data Structures
body: <p>I am doing an assignment for class and it requires me to Develop an algorithm using the Java programming language that implements a basic stack data structure.</p>
  
  <p>Here is the scenario: Assume that you are developing a system for a manufacturing assembly line that builds automobiles. There are three stations in the manufacturing line where an inspector will visually inspect the vehicle. You program must keep track of these inspections as they occur. You decided to develop your program using a stack data structure. As your vehicle begins the line you will push the number 0, which indicates that that an inspection has not yet occurred, onto the stack three subsequent times. At each station in the line you will pop one of the items off of the stack. Each time your algorithm pops an item from the stack you must print it out to the console using the system.out.println function. I will post my code below. Does my code represent this senario?</p>
  
  <p>My Code:</p>
  
  <pre><code>import jeliot.io.*;
  
  public class MyStack {
     private int maxSize;
     private long[] stackArray;
     private int top;
     public MyStack(int s) {
        maxSize = s;
        stackArray = new long[maxSize];
        top = -1;
     }
     public void push(long j) {
        stackArray[++top] = j;
     }
     public long pop() {
        return stackArray[top--];
     }
     public long peek() {
        return stackArray[top];
     }
     public boolean isEmpty() {
        return (top == -1);
     }
     public boolean isFull() {
        return (top == maxSize - 1);
     }
     public static void main(String[] args) {
        MyStack theStack = new MyStack(5); 
        theStack.push(0);
        theStack.push(1);
        theStack.push(2);
        theStack.push(3);
        theStack.push(4);
        while (!theStack.isEmpty()) {
           long value = theStack.pop();
           System.out.print(value);
           System.out.print(" ");
        }
        System.out.println("");
     }
   }
  </code></pre>
  
  <p>The assignment also came with a linked list example code. You can compare how my code works as to the example. Here is the code:</p>
  
  <pre><code>import Prog1Tools.IOTools;
  
  class Node {
     Node ptr;
     int value;
     public Node(int value) {
       this.value = value;
     }
  }
  
  public class CreateLinkedList {
    public static void main(String[] args) {
      Node link, plink;
      // root will be the beginning of the linked list
      Node root = new Node(5);
      // each additional node will link to preceeding one
      link = new Node(1);
      link.ptr = root;
      plink = link;
  
      link = new Node(8);
      link.ptr = plink;
      plink = link;
  
      link = new Node(6);
      link.ptr = plink;
      plink = link;
  
      link = new Node(3);
      link.ptr = plink;
      plink = link;
  
      // Move through the list and print out each value
      printList(link);
  }
  
  public static void printList(Node node) {
    if (node != null) {
      System.out.println(" Value: " + node.value);
      printList(node.ptr);
      }
    }
  }
  </code></pre>