fork download
  1. public class Main {
  2. public static void main(String[] args) {
  3. Stack vStack = new Stack();
  4.  
  5. vStack.push(2);
  6. vStack.push(1);
  7. vStack.push(0);
  8. // Simulate the inspection process
  9. System.out.println("Starting vehicle inspection...");
  10.  
  11. int station = 0;
  12.  
  13. while (vStack.top != null){
  14. station += 1;
  15. int status = vStack.pop();
  16. System.out.println("Testing Station " + station + " inspection status: " + status);
  17. }
  18.  
  19. System.out.println("Vehicle inspection process completed.");
  20.  
  21. }
  22.  
  23.  
  24. }
  25.  
  26. // Node class for the linked list
  27. class Node {
  28. int data;
  29. Node next;
  30.  
  31. // Constructor
  32. public Node(int data) {
  33. this.data = data;
  34. this.next = null;
  35. }
  36. }
  37.  
  38. class Stack {
  39. public Node top;
  40.  
  41. public void push(int value) {
  42. Node newNode = new Node(value);
  43. newNode.next = top;
  44. top = newNode;
  45. }
  46.  
  47. public int pop() {
  48. if (top == null) {
  49. return -1;
  50. }
  51. int poppedValue = top.data;
  52. top = top.next;
  53. return poppedValue;
  54. }
  55.  
  56.  
  57. }
  58.  
Success #stdin #stdout 0.15s 57596KB
stdin
Standard input is empty
stdout
Starting vehicle inspection...
Testing Station 1 inspection status: 0
Testing Station 2 inspection status: 1
Testing Station 3 inspection status: 2
Vehicle inspection process completed.