package search;

import java.util.Arrays;

/**
 * @author Nikita Doschennikov (me@fymio.us)
 */
public class IntList {

    protected int[] list = new int[8];
    protected int idx = 0;

    public IntList() {}

    public IntList(int[] list) {
        this.list = list;
    }

    public void put(int val) {
        if (idx >= list.length) {
            list = Arrays.copyOf(list, list.length * 2);
        }

        list[idx++] = val;
    }

    public int getLength() {
        return idx;
    }

    public int get(int index) {
        return list[index];
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < idx; i++) {
            if (i == idx - 1) {
                sb.append(String.valueOf(list[i]) + "\n");
            } else {
                sb.append(String.valueOf(list[i]) + " ");
            }
        }

        return sb.toString();
    }
}
