Skip to content

Instantly share code, notes, and snippets.

@bluepnume
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save bluepnume/ca40df02fa4420284c3f to your computer and use it in GitHub Desktop.

Select an option

Save bluepnume/ca40df02fa4420284c3f to your computer and use it in GitHub Desktop.
// Insert an element
// data = array
// currentSize = current size of array (??)
// newElement = the element to insert
// pos = the position to insert it
// If the array is bigger than currentSize (??)
if (currentSize < data.length)
{
// Loop down from currentSize to pos+1
for (int i = currentSize; i > pos; i--)
{
// Move the element up an index
data[i] = data[i - 1];
}
// Insert the new index at pos
data[pos] = newElement;
// Update our current size
currentSize++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment