Skip to content

Instantly share code, notes, and snippets.

@MrKomodoDragon
Created September 30, 2025 19:52
Show Gist options
  • Select an option

  • Save MrKomodoDragon/345bbf030d66bf86506f01b87b2f17b9 to your computer and use it in GitHub Desktop.

Select an option

Save MrKomodoDragon/345bbf030d66bf86506f01b87b2f17b9 to your computer and use it in GitHub Desktop.
Array with syntax highlighting
public class Array<E> {
public Unit[] arr;
public int size;
private int last_inserted = -1;
private class Unit<E> {
public E data;
Unit(E thing) {
this.data = thing;
}
}
Array(int size) {
this.size = size;
this.arr = new Unit[this.size];
}
public void append(E thing) {
if (last_inserted + 1 >= size) {
Unit[] temp_arr = new Unit[this.size * 2];
System.arraycopy(this.arr, 0, temp_arr, 0, this.size);
this.arr = temp_arr;
this.size *= 2;
}
last_inserted++;
Unit u = new Unit(thing);
this.arr[last_inserted] = u;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment