Skip to content

Dynamic Array #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

t0rr3sp3dr0
Copy link

Issue #96

Copy link

@christianbender christianbender left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Work! I have some requests.

import java.util.*;

public class DynamicArray<E> {
private Object[] array;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you don't use E instead of Object[]

}

private void resize() {
Object[] array = this.array;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use tmp instead of array. Because array can be confusing.
Why you don't use E instead of Object

if (this.size == array.length)
this.resize();

this.array[this.size++] = e;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must add this.size++

}

public void set(int index, E e) {
if (this.array[index] == null && e != null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use curly braces

}

public int indexOf(E e) {
for (int i = 0; i < this.size; i++)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use curly braces

if (this.array[i].equals(e))
return i;

return this.size;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you don't return -1?

public static void main(String[] args) {
DynamicArray<Integer> v = new DynamicArray<>(11);

for (int i = 0; i < 100; i++)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use curly braces


for (int i = 0; i < 100; i++)
v.add(i);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more test cases. For methodse set and add(index,e).

for (int i = 0; i < this.size; i++)
if (this.array[i].equals(e))
return i;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments in your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants