Is there a:
1> Vector(Java) class
2> ListIterator
3> Single Linkedlist
equivalent available in PHP?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
1) Any PHP array can be considered and used as a Vector (since by definition Vector is just an array that can grow in size and PHP doesn’t require to specify array size). As java documents it,
PHP array fulfills all there requirements.
2) There is an Iterator if you insist on it, but in general it is much more common to use loops for array traversing (just like you don’t really iterate arrays in Java with Iterator, do you?)
3) There is no list implementations in PHP in general (well, I bet internally arrays are implemented as a list/hashmap, but that’s only internally). You can go with one of two options. Either use array (do you see a pattern here – arrays FTW!) if you are only interested in sequential ordering of items (you get random access as a bonus), or you can implement your own completely-OO list with 2 small classes (I’d call them
ListandListCell)Addition to part 3: Don’t worry about insertions or deletions in the middle of the list, as those may be achieved with array_slice and array_splice. Insertion and deletion may not be O(1) timewise, but since in the list you would also need O(n) time for locating the place to insert in the list, I thing the options are comparable.