📄 lista.cpp
字号:
// *********************************************************// Implementation file ListA.cpp for the ADT list// Array-based implementation// *********************************************************#include "ListA.h" //header fileList::List() : size(0){} // end default constructorbool List::isEmpty() const{ return size == 0;} // end isEmptyint List::getLength() const{ return size;} // end getLengthvoid List::insert(int index, ListItemType newItem, bool& success){ success = (index >= 1) && (index <= size + 1) && (size < MAX_LIST); if (success) { // make room for new item by shifting all items at // positions >= index toward the end of the // list (no shift if index == size+1) for (int pos = size; pos >= index; --pos) items[translate(pos+1)] = items[translate(pos)]; // insert new item items[translate(index)] = newItem; ++size; // increase the size of the list by one } // end if} // end insertvoid List::remove(int index, bool& success){ success = (index >= 1) && (index <= size) ; if (success) { // delete item by shifting all items at positions > // index toward the beginning of the list // (no shift if index == size) for (int fromPosition = index+1; fromPosition <= size; ++fromPosition) items[translate(fromPosition-1)] = items[translate(fromPosition)]; --size; // decrease the size of the list by one } // end if} // end removevoid List::retrieve(int index, ListItemType& dataItem, bool& success) const{ success = bool( (index >= 1) && (index <= size) ); if (success) dataItem = items[translate(index)];} // end retrieveint List::translate(int index) const{ return index-1;} // end translate// End of implementation file.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -