Complete Java Implementation

Access all Java source code files used in the visualizations. Each file contains a complete implementation ready for learning and modification with detailed explanations and examples.

4 Implementations
1 Categories
300+ Lines of Code

Linear Data Structures

📊

Dynamic Array

A complete implementation of a dynamic array with automatic resize functionality and efficient operations.

🔢 Operations: Insert, Delete, Search
⚙️ Features: Dynamic Resizing
📏 Lines: ~70
Array.java
public class Array<T> {
    private Object[] array;
    private int size;
    private int capacity;

    public Array() {
        capacity = 5;
        array = new Object[capacity];
        size = 0;
    }

    public void insert(T element) {
        if (size == capacity) {
            resize();
        }
        array[size] = element;
        size++;
    }

    public boolean delete(T element) {
        int index = search(element);
        if (index == -1) {
            return false;
        }
        shiftLeft(index);
        size--;
        return true;
    }

    public int search(T element) {
        for (int i = 0; i < size; i++) {
            if (array[i].equals(element)) {
                return i;
            }
        }
        return -1;
    }

    private void resize() {
        capacity *= 2;
        Object[] newArray = new Object[capacity];
        for (int i = 0; i < size; i++) {
            newArray[i] = array[i];
        }
        array = newArray;
    }

    private void shiftLeft(int index) {
        for (int i = index; i < size; i++) {
            array[i] = array[i + 1];
        }
    }

    public int size() {
        return size;
    }
}
🔗

Linked List

Singly and doubly linked lists with efficient pointer manipulation and traversal operations.

🔢 Operations: Insert Head, Insert Tail, Insert At Index, Delete, Search
⚙️ Features: Dynamic Size
📏 Lines: ~90
LinkedList.java
public class LinkedList {
    private Node head;
    private int size = 0;
    private class Node {
        T data;
        Node next;
        Node(T data) {
            this.data = data;
            this.next = null;
        }
    }

    public void insertAtHead(T data) {
        Node newNode = new Node<>(data);
        newNode.next = head;
        head = newNode;
        size++;
    }

    public void insertAtTail(T data) {
        Node newNode = new Node<>(data);
        if (head == null) {
            insertAtHead(data);
            return;
        }
        Node current = head;
        while (current.next != null) {
            current = current.next;
        }
        current.next = newNode;
        size++;
    }

    public void insertAtIndex(int index, T data) {
        if (index < 0 || index > size) {
            return;
        }
        if (index == 0) {
            insertAtHead(data);
            return;
        }
        Node newNode = new Node<>(data);
        Node current = head;
        for (int i = 0; i < index - 1; i++) {
            current = current.next;
        }
        newNode.next = current.next;
        current.next = newNode;
        size++;
    }

    public boolean delete(T data) {
        if (head == null) {
            return false;
        }
        if (head.data.equals(data)) {
            head = head.next;
            size--;
            return true;
        }
        Node current = head;
        while (current.next != null) {
            if (current.next.data.equals(data)) {
                current.next = current.next.next;
                size--;
                return true;
            }
            current = current.next;
        }
        return false;
    }

    public int search(T data) {
        Node current = head;
        int index = 0;
        while (current != null) {
            if (current.data.equals(data)) {
                return index;
            }
            current = current.next;
            index++;
        }
        return -1;
    }

    public int size() {
        return size;
    }
}
📚

Stack

A dynamic array-based implementation of a LIFO stack with automatic resizing capabilities.

🔢 Operations: Push, Pop, Peek
⚙️ Features: Dynamic Resizing
📏 Lines: ~50
Stack.java
public class Stack {
    private Object[] stack;
    private int size;
    private int capacity;
    private int top;

    public Stack() {
        this.capacity = 5;
        this.stack = new Object[this.capacity];
        this.size = 0;
        this.top = -1;
    }

    private void resize() {
        int newCapacity = capacity * 2;
        this.stack = Arrays.copyOf(this.stack, newCapacity);
        this.capacity = newCapacity;
    }

    public void push(T data) {
        if (size == capacity) {
            resize();
        }
        top++;
        stack[top] = data;
        size++;
    }

    public T pop() {
        if (isEmpty()) {
            return null;
        }
        T data = (T) stack[top];
        stack[top] = null;
        top--;
        size--;
        return data;
    }

    public T peek() {
        if (isEmpty()) {
            return null;
        }
        return (T) stack[top];
    }

    public boolean isEmpty() {
        return size == 0;
    }
    
    public int size() {
        return size;
    }
}
↔️

Deque

A circular array implementation of a double-ended queue with efficient front and rear operations.

🔢 Operations: Add At First, Add At Last, Remove At First, Remove At Last, Peek At First, Peek At Last
⚙️ Features: Circular, Resizing
📏 Lines: ~110
Deque.java
public class Deque<T> {
    private Object[] deque;
    private int size;
    private int capacity;
    private int front;
    private int rear;

    public Deque() {
        capacity = 5;
        deque = new Object[capacity];
        size = 0;
        front = -1;
        rear = -1;
    }

    public boolean isFull() {
        return size == capacity;
    }

    public boolean isEmpty() {
        return size == 0;
    }

    private void resize() {
        int newCapacity = capacity * 2;
        Object[] newDeque = new Object[newCapacity];
        int i = 0;
        int j = front;
        while (i < size) {
            newDeque[i] = deque[j];
            j = (j + 1) % capacity;
            i++;
        }
        deque = newDeque;
        capacity = newCapacity;
        front = 0;
        rear = size - 1;
    }

    public void addFirst(T element) {
        if (isFull()) {
            resize();
        }
        if (isEmpty()) {
            front = 0;
            rear = -1;
        } else {
            front = (front - 1 + capacity) % capacity;
        }
        deque[front] = element;
        size++;
    }

    public void addLast(T element) {
        if (isFull()) {
            resize();
        }
        if (isEmpty()) {
            front = 0;
            rear = -1;
        } else {
            rear = (rear + 1) % capacity;
        }
        deque[rear] = element;
        size++;
    }

    public T removeFirst() {
        if (isEmpty()) {
            return null;
        }
        T element = (T) deque[front];
        deque[front] = null;
        size--;
        if (isEmpty()) {
            front = -1;
            rear = -1;
        } else {
            front = (front + 1) % capacity;
        }
        return element;
    }

    public T removeLast() {
        if (isEmpty()) {
            return null;
        }
        T element = (T) deque[rear];
        deque[rear] = null;
        size--;
        if (isEmpty()) {
            front = -1;
            rear = -1 ;
        } else {
            rear = (rear - 1 + capacity) % capacity;
        }
        return element;
    }

    public T peekFirst() {
        if (isEmpty()) {
            return null;
        }
        return (T) deque[front];
    }

    public T peekLast() {
        if (isEmpty()) {
            return null;
        }
        return (T) deque[rear];
    }

    public int size() {
        return size;
    }
}

Tree Data Structures

🌳

Binary Search Tree

Self-organizing tree with efficient search, insertion, and deletion operations.

Coming Soon
⚖️

AVL Tree

Self-balancing binary search tree with automatic rotations for optimal performance.

Coming Soon
⛰️

Heap

Complete binary tree with heap property maintenance for priority queue operations.

Coming Soon
🔤

Trie

Prefix tree for efficient string operations, autocomplete, and dictionary implementations.

Coming Soon

Download Complete Collection

Get all available Java source files in a single download for offline learning and modification. Includes documentation, examples, and test cases.

4 Available Files
300+ Lines of Code
MIT License