Java Queue tutorial

A queue is an ADT – Abstract Data Type or a linear data structure. It is a FIFO data structure because element inserted first will be removed first. FIFO stands for First-in-first-out. Queue use one end to insert data which is called REAR or tail and other end to remove the data which is called … Read more

Java towers of hanoi stack implementation

Examples package com.w3schools;   public class Test { private static Test[] tower; private int stackSize; private int[] stackArray; private int top;   /** * constructor to create stack with size * @param size */ public Test(int size) { this.stackSize = size; this.stackArray = new int[stackSize]; this.top = -1; }   /** * Adds new entry … Read more

Java convert a decimal number to binary using stack

Examples package com.w3schools;   public class Test { private int stackSize; private int[] stackArray; private int top;   /** * constructor to create stack with size * @param size */ public Test(int size) { this.stackSize = size; this.stackArray = new int[stackSize]; this.top = -1; }   /** * Adds new entry to the top of … Read more

Java delimiter matching using stack

Examples package com.w3schools;   public class Test { private int stackSize; private char[] stackArray; private int top;   /** * constructor to create stack with size * @param size */ public Test(int size) { this.stackSize = size; this.stackArray = new char[stackSize]; this.top = -1; }   /** * Adds new entry to the top of … Read more

Java reverse a string using stack

Examples package com.w3schools;   public class Test { private int stackSize; private char[] stackArray; private int top;   /** * constructor to create stack with size * @param size */ public Test(int size) { this.stackSize = size; this.stackArray = new char[stackSize]; this.top = -1; }   /** * Adds new entry to the top of … Read more

Java generic stack implementation

Examples package com.w3schools;   public class Test<T extends Object> { private int stackSize; private T[] stackArray; private int top;   /** * constructor to create stack with size * @param size */ public Test(int size) { this.stackSize = size; this.stackArray = (T[]) new Object[stackSize]; this.top = -1; }   /** * Adds new entry to … Read more

Java dynamic stack implementation

Dynamic Stack As we discussed in previous example that a stack throws an exception if enough space is not available to accept an entity to be pushed. To overcome this situation we can create dynamic stack whose capacity will keep increases as it reaches to max capacity. Examples package com.w3schools;   public class Test { … Read more

Java stack implementation

Examples package com.w3schools;   public class Test { private int stackSize; private int[] stackArr; private int top;   /** * constructor to create stack with size * @param size */ public Test(int size) { this.stackSize = size; this.stackArr = new int[stackSize]; this.top = -1; }   /** * Adds new entry to the top of … Read more

Java Stack tutorial

A stack is an ADT – Abstract Data Type or a linear data structure. It is a LIFO data structure because it allows all data operations at one end only i.e. elements can be added and removed from the stack only at the top. LIFO stands for Last-in-first-out. The element which is inserted last, is … Read more

Java merge sort algorithm example

Sorting algorithm A sorting algorithm is a way to put elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms (like search and merge algorithms) which require input data to be in sorted lists. It is also … Read more