Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. public void insertAtEnd(int val) {
  2. if(numElements == length) { //if the length is equal to the numElements.
  3. length = 2 * length; //Double the length.
  4. int B[] = new int[length]; //Create a new array of with the updated length.
  5. for(int i=0; i<numElements; i++) { //For loop which runs numElements of times.
  6. B[i] = A[i]; //Transfer the elements of A[] into B[]
  7. }
  8. A = B;
  9. }
  10. A[numElements++] = val; //Set the value at the end of the array while incrementing numElements.
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement