Data Structure Design

Copyright © 直通硅谷

http://www.zhitongguigu.com/

Design a stock api

Design a stock api

class System { // assume time being used is unique
public:
    int getMax() {} //O(1)
    
    int getMin() {} //O(1)
    
    int getRecent() {} //O(1)
    
    void add(long time, int price) {}
    
    void update(long time, int price) {}
    
    void remove(long time) {}
    
private:

};

Design an array api

Design a array api

Get, Set, SetAll // All operation is O(1)

Get(4) -> get element at index 4
Set(index, value);
SetAll(5) -> set all element to 5

class Array{
private:
public:
    Status Get(int index){}
    void Set(int index, int val){}
    void SetAll(int val){}
};

Copyright © 直通硅谷

http://www.zhitongguigu.com/

Homework

Copyright © 直通硅谷

http://www.zhitongguigu.com/

Homework

[GoValley-201612] Data Structure Design

By govalley201612

[GoValley-201612] Data Structure Design

  • 683