1: // Removes and returns the entry at a given index within the array bag. 2: // If no such entry exists, returns null. 3: // Preconditions: 0 <= givenIndex < numberOfEntries; 4: // checkInitialization has been called. 5: private T removeEntry(int givenIndex) 6: { 7: T result = null; 8: 9: if (!isEmpty() && (givenIndex >= 0)) 10: { 11: result = bag[givenIndex]; // Entry to remove 12: bag[givenIndex] = bag[numberOfEntries - 1]; // Replace entry with last entry 13: bag[numberOfEntries - 1] = null; // Remove last entry 14: numberOfEntries--; 15: } // end if 16: 17: return result; 18: } // end removeEntry