所以我试图为一个名为uls的项目创建自己的数据类型。ULS基本上是一个100根据列表的大小,由于每个房屋列表都可能因城市而异,因此我尝试根据给定列表的大小实现不同的抽象数据类型见下文:

    Algorithm setSmartThresholdULS(Size):
Input: Integer Size that defines the list size.
Ouput: Data structure implemented with the given size

Int Threshold <- 1000

If Size is smaller than Threshold then
    setSmartThresholdULS(Size) extends AbstractHashMap<K,V>

Else if Size is greater than Threshold then
    setSmartThresholdULS(Size) extends AVLTreeMap<K,V>

这只是伪代码,但我如何实现语法正确的呢上面的代码是否合法/有效?

最佳答案

是的,可以根据情况创建不同的数据结构这通常是用工厂模式完成的。不,对于较大的数据集使用可伸缩性较差的数据结构没有任何意义。

07-24 19:12
查看更多