diff --git a/NoDuplicationArray.java b/NoDuplicationArray.java new file mode 100644 index 0000000..5c1ae0f --- /dev/null +++ b/NoDuplicationArray.java @@ -0,0 +1,71 @@ +package noduplicationarray; + +public class NoDuplicationArray { + private long[] a; + private int n; // number of elements + + public NoDuplicationArray(int max) { + this.a = new long[max]; // initialing an array + this.n = 0; // initial number of elements + } + + public boolean find(long key) { // finding if a particular number present in the array + for (int i = 0; i < this.n; i++) + { + if (this.a[i] == key) { + return true; + } + } + return false; + } + + public void insert(long value) { // inserting elements to the array + if (this.n == a.length) { + System.out.println("This array is already filled"); + return; + } else { + if (find(value)) { + System.out.println("Value is already in the array,insertion terminated"); + } else { + a[this.n] = value; + this.n++; + } + } + } + + public boolean delete(long value){ + for(int i=0;i