簡體   English   中英

創建自己的數據結構 class 還是使用現有的實現?

[英]Create your own data structure class or use existing implementation?

所以我一直在研究數據結構,我可以創建自己的鏈表 class 及其功能(插入、刪除、長度等),但是當我可以簡單地執行以下操作時,為什么要這樣做

LinkedList<>list = new LinkedList<>();

該問題的一個很好的理由是:Spring 模型或 Spring POJO。

It can be troublesome to have bean of type Map in old Spring for example and autowire it, but if you create a class that extends Map or that failing type then it will work:

public class MyDataContainer extends Map<int, String> {
...
}

另一種用途是當您想對 get 或 set 執行自定義操作時,擴展 Data Structure 類型並覆蓋其中一個 getter 或 setter 可能很有用,例如:在設置或將其放入List之前從多余的空格中Map ,或您修改過的任何數據結構。 在我的職業生涯中,我實際上不得不這樣做幾次。

Generally, this question asked in an interview, design the functionality for LinkedList. 
If you have deep knowledge of LinkedList, then you can design the LinkedList for different languages.
Custom LinkedList implementation will check your deep understanding, how it works internally.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM