content: // Node class for linked list
  class Node {
      int data;
      Node next;
  
      Node(int data) {
          this.data = data;
          this.next = null;
      }
  }
  
  // Stack class using linked list
  class Stack {
      private Node top;
  
      public Stack() {
          top = null;
      }
  
      // Push operation
      public void push(int value) {
          Node newNode = new Node(value);
          newNode.next = top;
          top = newNode;
          System.out.println("Pushed: " + value);
      }
  
      // Pop operation
      public int pop() {
          if (isEmpty()) {
              throw new RuntimeException("Stack Underflow");
          }
          int value = top.data;
          top = top.next;
          System.out.println("Popped: " + value);
          return value;
      }
  
      // Peek operation
      public int peek() {
          if (isEmpty()) {
              throw new RuntimeException("Stack is empty");
          }
          return top.data;
      }
  
      // Check if stack is empty
      public boolean isEmpty() {
          return top == null;
      }
  
      // Display stack contents
      public void display() {
          if (isEmpty()) {
              System.out.println("Stack is empty");
              return;
          }
          Node current = top;
          System.out.print("Stack (top to bottom): ");
          while (current != null) {
              System.out.print(current.data + " ");
              current = current.next;
          }
          System.out.println();
      }
  }
  
  // Main class to test the stack
  public class UsingLinkedList {
      public static void main(String[] args) {
          Stack stack = new Stack();
  
          stack.push(10);
          stack.push(20);
          stack.push(30);
  
          stack.display(); // Stack: 30 20 10
  
          System.out.println("Top element: " + stack.peek()); // Top: 30
  
          stack.pop(); // Popped: 30
          stack.display(); // Stack: 20 10
  
          stack.pop(); // Popped: 20
          stack.pop(); // Popped: 10
  
          stack.display(); // Stack is empty
      }
  }
  