Skip to content

Conversation

@luqp
Copy link
Owner

@luqp luqp commented May 28, 2018

Two new projects, the first is about of configurate list with help from array, and second is the test of the first

…om array, and second is the test of the first
@luqp luqp added the good first issue Good for newcomers label May 28, 2018
@luqp luqp self-assigned this May 28, 2018
@luqp luqp requested a review from uabarahona May 28, 2018 17:41
items = new T[5];
count = 0;
}
public List(int index)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This constructor should receive the initial quantity, so when you crea a new object new List<int>(15) you are saying that you want a List that have initially 15 espaces to fill

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes, but in really that is only to allow insert a number at create a new list.

public List(int index)
{
items = new T[index];
count = index;
Copy link
Collaborator

Choose a reason for hiding this comment

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

As I said before you should receive quantity and not the index, and also count = index is bad, with quantity you say that you want a list that have initially X spaces, but that does not mean that you have X items, at this point you have 0 items.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes, I forgot it, I will fix it

{
items[count] = item;
count++;
if (count == items.Length)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This logic should be first in the method, for example if I create a list of 15 spaces new List<int>(15) and then I insert elements until fill those 15 spaces, you are incrementing the array immediately after I insert the 15 element, but that is wrong in my particular case: I explicitly said that I want 15 spaces new List<int>(15) because I will make sure that my code does not insert more than 15 elements, and if I will not insert more than 15 elements why should I have a List that internally have an array with more than 15 elements.

If this logic is at the start, you will make sure to increment the list only if the user decide to put a 16 element.

Copy link
Owner Author

Choose a reason for hiding this comment

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

You say that the logic of line 25 should be begin before line 23...
Well, now that I see it, I think the same, I'll fix it.

Lucero added 2 commits May 28, 2018 15:55
…e according to the context, 2 Counter always starting in zero when created a new list without items, 3 Modificated the ording of the metod Add()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants