| Index: src/list-inl.h
|
| diff --git a/src/list-inl.h b/src/list-inl.h
|
| index e277bc87234434480bd49430b3ce70756f612199..eeaea65f80b61343c91f06b5299b69201c784265 100644
|
| --- a/src/list-inl.h
|
| +++ b/src/list-inl.h
|
| @@ -96,6 +96,17 @@ Vector<T> List<T, P>::AddBlock(T value, int count) {
|
|
|
|
|
| template<typename T, class P>
|
| +void List<T, P>::InsertAt(int index, const T& elm) {
|
| + ASSERT(index >= 0 && index <= length_);
|
| + Add(elm);
|
| + for (int i = length_ - 1; i > index; --i) {
|
| + data_[i] = data_[i - 1];
|
| + }
|
| + data_[index] = elm;
|
| +}
|
| +
|
| +
|
| +template<typename T, class P>
|
| T List<T, P>::Remove(int i) {
|
| T element = at(i);
|
| length_--;
|
| @@ -108,6 +119,18 @@ T List<T, P>::Remove(int i) {
|
|
|
|
|
| template<typename T, class P>
|
| +bool List<T, P>::RemoveElement(const T& elm) {
|
| + for (int i = 0; i < length_; i++) {
|
| + if (data_[i] == elm) {
|
| + Remove(i);
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +
|
| +template<typename T, class P>
|
| void List<T, P>::Clear() {
|
| DeleteData(data_);
|
| Initialize(0);
|
| @@ -134,7 +157,7 @@ void List<T, P>::Iterate(Visitor* visitor) {
|
|
|
|
|
| template<typename T, class P>
|
| -bool List<T, P>::Contains(const T& elm) {
|
| +bool List<T, P>::Contains(const T& elm) const {
|
| for (int i = 0; i < length_; i++) {
|
| if (data_[i] == elm)
|
| return true;
|
| @@ -144,6 +167,16 @@ bool List<T, P>::Contains(const T& elm) {
|
|
|
|
|
| template<typename T, class P>
|
| +int List<T, P>::CountOccurrences(const T& elm, int start, int end) const {
|
| + int result = 0;
|
| + for (int i = start; i <= end; i++) {
|
| + if (data_[i] == elm) ++result;
|
| + }
|
| + return result;
|
| +}
|
| +
|
| +
|
| +template<typename T, class P>
|
| void List<T, P>::Sort(int (*cmp)(const T* x, const T* y)) {
|
| ToVector().Sort(cmp);
|
| #ifdef DEBUG
|
|
|