Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void insertAtEnd(int val) {
- if(numElements == length) { //if the length is equal to the numElements.
- length = 2 * length; //Double the length.
- int B[] = new int[length]; //Create a new array of with the updated length.
- for(int i=0; i<numElements; i++) { //For loop which runs numElements of times.
- B[i] = A[i]; //Transfer the elements of A[] into B[]
- }
- A = B;
- }
- A[numElements++] = val; //Set the value at the end of the array while incrementing numElements.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement