Skip to content

Instantly share code, notes, and snippets.

@jp26jp
Last active September 16, 2017 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jp26jp/1c40bd51a0fb94c13e042eed9fd4a229 to your computer and use it in GitHub Desktop.
Save jp26jp/1c40bd51a0fb94c13e042eed9fd4a229 to your computer and use it in GitHub Desktop.
/**
* We figured out part of the answer to our question.
* So now we'd just like to know if we're on the right track.
*/
public void insert(int index, E data)
{
ensureCapacity(indexCounter + 1);
for (int i = elementData.length; i > index; i--)
{
int currentIdx = (i + elementData.length - 1) % elementData.length;
int nextIdx = (i + 1 + elementData.length - 1) % elementData.length;
elementData[nextIdx] = elementData[currentIdx];
System.out.println(elementData[currentIdx] + " moved to index: " + nextIdx);
modCounter++;
}
indexCounter++;
setElement(index, data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment