-
Notifications
You must be signed in to change notification settings - Fork 0
Data Structures #1
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
base: master
Are you sure you want to change the base?
Conversation
…om array, and second is the test of the first
DataStructures/List.cs
Outdated
| items = new T[5]; | ||
| count = 0; | ||
| } | ||
| public List(int index) |
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.
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
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.
Yes, but in really that is only to allow insert a number at create a new list.
DataStructures/List.cs
Outdated
| public List(int index) | ||
| { | ||
| items = new T[index]; | ||
| count = index; |
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.
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.
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.
Yes, I forgot it, I will fix it
| { | ||
| items[count] = item; | ||
| count++; | ||
| if (count == items.Length) |
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.
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.
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.
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.
…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()
Two new projects, the first is about of configurate list with help from array, and second is the test of the first