Skip to main content

Posts

Showing posts with the label generic

Queue using Stack

import java.io.*; //Node--------------- class Node<T> {     T value;     Node<T> link; } // Stack--------------- class Stack<T> {     Node<T> top;     public Stack() {         top = null;     }     public void push(T item) {         Node<T> n = new Node<T>();         n.value = item;         n.link = top;         top = n;     }     public T pop() {         T item;         item = top.value;         Node<T> n = top;         n = null;         top = top.link;         return item; ...

Generic Stack

import java.io.*; class Node<T> {     T value;     Node<T> link; } class Stack<T> {     Node<T> top;     public Stack() {         top = null;     }     public void push(T item) {         Node<T> n = new Node<T>();         n.value = item;         n.link = top;         top = n;     }     public T pop() {         T item;         item = top.value;         Node<T> n = top;         n = null;         top = top.link;         return item;     }     p...