diff --git a/src/DynArray.java b/src/DynArray.java index 10f7339e490480dbe708abb7343f4e50c22d231e..9ff05ff3e7e97115f2d7ee436004beb813e77e5f 100644 --- a/src/DynArray.java +++ b/src/DynArray.java @@ -14,11 +14,24 @@ public class DynArray { } public DynArray() { + this.capacity = this.basev; this.array = new Contact[this.capacity]; this.size = 0; } - public void append(Contact[] a) { + // public void append(Contact[] a) { + // make_sure_size(a); // REALLOC IF NEEDED + // this.size += a.length; + // int s = this.size; + + // // Add the new values + // for (int i = s; i < s + a.length; i++) { + // // System.out.println("arr[" + (i - a.length) + "] = " + a[i - s]); + // this.array[i - a.length] = a[i - s]; + // } + // } + + public void append(Contact... a) { make_sure_size(a); // REALLOC IF NEEDED this.size += a.length; int s = this.size; @@ -39,7 +52,7 @@ public class DynArray { } public void make_sure_size(Contact[] a) { - if ((this.size + a.length) > this.capacity) // Overflow? + if ((this.size + a.length) >= this.capacity) // Overflow? { // Realloc new array this.capacity *= 2; @@ -50,17 +63,17 @@ public class DynArray { } } - public void make_sure_size(Contact a) { - if ((this.size + 1) > this.capacity) // Overflow? - { - // Realloc new array - this.capacity *= 2; - Contact[] new_arr = new Contact[this.capacity]; - copy_content(this.array, new_arr); + // public void make_sure_size(Contact a) { + // if ((this.size + 1) > this.capacity) // Overflow? + // { + // // Realloc new array + // this.capacity *= 2; + // Contact[] new_arr = new Contact[this.capacity]; + // copy_content(this.array, new_arr); - this.array = new_arr; // Copy pointer - } - } + // this.array = new_arr; // Copy pointer + // } + // } public void show_it() { System.out.println(this.toString()); @@ -71,7 +84,7 @@ public class DynArray { for (int i = 0; i < this.size; i++) { s = s.concat(array[i].toShortString()); - s = s.concat(",\n"); + s = s.concat("\n"); } return s; } diff --git a/src/Main.java b/src/Main.java index 816b63ab44cb504399367ccb2a4fd46c82d00700..54f3aea7c6f1e8d18e2953cdfdc286eb20234444 100644 --- a/src/Main.java +++ b/src/Main.java @@ -12,13 +12,14 @@ public class Main { Contact c2 = new Contact(); Contact c3 = new Contact("fnamekek", "joseph"); - c1.show(); - c2.show(); - c3.show(); - System.out.println(c1.toShortString()); - c2.showShort(); + // c1.show(); + // c2.show(); + // c3.show(); + // System.out.println(c1.toShortString()); + // c2.showShort(); - //DynArray contacts = new DynArray(); - //contacts.append(); + DynArray contacts = new DynArray(); + contacts.append(c1, c2, c3); + System.out.println(contacts.toString()); } }