| 8 | import java.util.*; |
| 9 | |
| 10 | class GSSArray |
| 11 | { |
| 12 | private int [] arr; |
| 13 | private int size; |
| 14 | private int lastIndex = -1; |
| 15 | |
| 16 | //default constructor |
| 17 | GSSArray(int n) |
| 18 | { |
| 19 | arr = new int[n]; |
| 20 | size = n; |
| 21 | } |
| 22 | |
| 23 | int i = 0; |
| 24 | |
| 25 | //insert function |
| 26 | public void insert(int value) |
| 27 | { |
| 28 | //if size is less than defined size regular addition |
| 29 | if (size > i) |
| 30 | { |
| 31 | lastIndex++; |
| 32 | arr[lastIndex] = value; |
| 33 | i++; |
| 34 | display(); |
| 35 | } |
| 36 | |
| 37 | //if the size is more then it first increases the size and then performs addition in the array |
| 38 | else |
| 39 | { |
| 40 | increaseSize(); |
| 41 | lastIndex++; |
| 42 | arr[lastIndex] = value; |
| 43 | i++; |
| 44 | display(); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | //incrase size function - it doubles the size and copie the elements of old array in the new array |
| 49 | private void increaseSize() |
| 50 | { |
| 51 | int[] arr1 = new int[arr.length*2]; |
| 52 | for(int i=0;i<arr.length;i++) |
| 53 | { |
| 54 | arr1[i] = arr[i]; |
| 55 | } |
| 56 | |
| 57 | arr=arr1; |
| 58 | } |
| 59 | |
| 60 | //to check whether the element to be delted is present in the array is present or not |
| 61 | public boolean delete(int value) |
| 62 | { |
| 63 | int pos = -1; |
| 64 | for (int index = 0; index < lastIndex; index++) |
| 65 | { |
| 66 | if (arr[index] == value) |
| 67 | { |
nothing calls this directly
no outgoing calls
no test coverage detected