[CareerCup] 14.6 CircularArray 环形数组 - Grandyang - 博客园
[CareerCup] 14.6 CircularArray 环形数组
14.6 Implement a CircularArray class that supports an array-like data structure which can be efficiently rotated.The class should use a generic type, and should support iteration via the standard for (Obj o : CircularArray) notation.
这道题让我们实现一个环形数组类CircularArray,由于环形数组需要调用rotate(int shiftRight)函数,在这里,我们并不会真的去旋转数组,因为这样十分不高效。我们采用另一种实现方法,用一个变量head来记录环形数组的起始位置,那么调用rotate实际上就是改变head的位置而已
Read full article from [CareerCup] 14.6 CircularArray 环形数组 - Grandyang - 博客园
No comments:
Post a Comment