-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
done #1557
base: master
Are you sure you want to change the base?
done #1557
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this implementation! 😊 While your code meets most of the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:
-
Unnecessary Resizing in
remove(int index)
: The call toifFullResize()
in theremove
method is not needed since resizing is not required when removing elements. Removing this will enhance the efficiency of your code. -
Redundant Index Check in
add(T value, int index)
: The index checkif (index >= 0 && index <= size)
is redundant becausevalidateIndexForAdd(index)
already ensures the index is within bounds. Simplifying this will improve the clarity of your code.
Please address these issues to ensure your code is both efficient and clear. Once these changes are made, your solution will be ready for approval. Keep up the great work, and don't hesitate to reach out if you have any questions! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
ifFullResize(); | ||
if (index >= 0 && index <= size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The index check if (index >= 0 && index <= size)
is redundant because validateIndexForAdd(index)
already ensures the index is within bounds. You can remove this check.
} | ||
|
||
@Override | ||
public T remove(int index) { | ||
return null; | ||
validateIndex(index); | ||
ifFullResize(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to ifFullResize()
is unnecessary in the remove(int index)
method. Resizing is not needed when removing elements, so this line can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Summary
Great job on implementing the ArrayList
class! 🎉 Your code meets most of the task requirements and constraints, and you've made significant improvements by addressing some key issues:
-
Unnecessary Resizing in
remove(int index)
: You've correctly removed the unnecessary call toifFullResize()
, which is not needed when removing elements. -
Redundant Index Check in
add(T value, int index)
: The redundant index check has been removed, simplifying the code and improving clarity.
However, there are a couple of areas that could still be improved:
-
Magic Numbers: The initial capacity of the array is hardcoded as
10
. Consider defining this as a constant with a descriptive name to enhance code readability. -
Use of
System.arraycopy()
: For better efficiency, consider usingSystem.arraycopy()
for moving array elements.
Your exception messages are informative, which is a good practice, and there are no unrelated files in your submission.
While the decision is to APPROVE this pull request to help you move forward with your learning, please take the time to address the mentioned issues. Improving these aspects will enhance your code's efficiency and readability. Keep up the great work, and continue learning from your experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
private int size; | ||
|
||
public ArrayList() { | ||
elements = new Object[10]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10 is a magic number, create constant
|
||
public ArrayList() { | ||
elements = new Object[10]; | ||
size = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int type = 0 by default
size = 0; |
|
||
validateIndexForAdd(index); | ||
ifFullResize(); | ||
for (int i = size; i > index; i--) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use System.arraycopy
return null; | ||
validateIndex(index); | ||
T removedElement = (T) elements[index]; | ||
for (int i = index; i < size - 1; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
if (elements[i] != null && elements[i].equals(element) | ||
|| elements[i] == null && element == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (elements[i] != null && elements[i].equals(element) | |
|| elements[i] == null && element == null) { | |
if (elements[i] != null && elements[i].equals(element) | |
|| elements[i] == element) { |
} | ||
|
||
private void resize() { | ||
elements = Arrays.copyOf(elements, elements.length + (elements.length / 2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.