Java deque implementation using doubly linked list

Deque Queue Double-ended queue is an abstract data type. A deque represents a linear collection of elements that support insertion, retrieval and removal of elements at both ends. Dequeue, often abbreviated to deque. Example package com.w3schools;   class Node<T>{ private Node<T> prev; private Node<T> next; private T value;   public Node<T> getPrev() { return prev; … Read more

Java PriorityQueue implementation

PriorityQueue Queue PriorityQueue extends AbstactQueue. PriorityQueue is a type of queue but not provide the FIFO facility to its elements. It not allows the null elements. A PriorityQueue is like a normal queue but each element has a priority associated with it. Example package com.w3schools;   public class Test { @SuppressWarnings("rawtypes") private Comparable[] pQueue; private … Read more

Java deque implementation

Deque Queue Double-ended queue is an abstract data type. A deque represents a linear collection of elements that support insertion, retrieval and removal of elements at both ends. Dequeue, often abbreviated to deque. This general data class has some possible sub-types: input-restricted deque: It is one where deletion can be made from both ends, but … Read more

Java dynamic queue implementation

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

Java queue implementation

Examples package com.w3schools;   public class Test { private int capacity; int queueArray[]; int front = 0; int rear = -1; int currentSize = 0;   public Test(int queueSize){ this.capacity = queueSize; queueArray = new int[this.capacity]; }   /** * Adds element at the end of the queue. * @param item */ public void enqueue(int … Read more

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