![]() But on the other end fact, all immutable data structures are missing (linked list, doubly linked list, heap, finger trees and more). Sure, bad Java mutable data structures should not be reproduced. On the contrary, it may be the worst thing to do with a linked list, depending upon how it is implemented. And no, fast injection of elements inside the list is not the only thing LinkedList is good for. In my opinion, using “non modifiable” lists as if they where immutable, or using mutable lists when you need immutable ones, is far more dangerous than using immutable, data sharing, linked lists, specifically if the “dangerous” operations have not been implemented on them. If yes, we set found to true and break from the loop. Now, we use a for-in loop to iterate through all elements of num and check individually if toFind is equal to n or not. Likewise, the number to be found is stored in toFind. How should we do it? Should we use a mutable list? But what if we need to share the list? Or simply reuse it later? Should we make defensive copies? In the above program, we have an array of integers stored in variable num. Adding an element in front of a “non-modifiable” list is painful and inefficient. They are easy to implement, but it would be better if they were standard, since they are much better for some use cases than what Kotlin offers. Immutable linked lists are missing in Kotlin. They are not for accessing elements by index or for some bulk operations like reversing. ![]() Linked lists are extremely efficient for sequentially accessing elements from one end or for adding elements to one end.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |