繁体   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