insert is the only useful linked list function your interface offers (disregarding isEmpty, printList, etc as useful but trivial). Without constant time front and back adds, removals and peeks, I can't foresee a reason to use this class instead of a primitive array. Anything in the middle is of no concern, and libraries that offer access to these elements, such as Java's LinkedList collection are generally considered to be flawed because clients may make false assumptions about the time complexity of provided operations. The whole point of linked lists is to offer fast insertion and removal of front and back elements, regardless of what those elements might be. This sort of function that takes an element and searches the structure for it is best used for hashes with random access. It's not obvious what functionality this class offers over, say, a primitive array.Ĭonsider remove(item). This is debatable, because it restricts your internal logic from distinguishing between null and undefined or other falsey values, but if you trust yourself to be consistent about it, I prefer the cleaner look.Īs written, I find your provided function interface insufficient for typical linked list needs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |