c08p412b.txt

来自「Data Abstraction & Problem Solving with 」· 文本 代码 · 共 50 行

TXT
50
字号
SortedList::SortedList(){}  // end default constructorSortedList::SortedList(const SortedList& sList):                       List(sList){}  // end copy constructorSortedList::~SortedList(){}  // end destructorvoid SortedList::sortedInsert(ListItemType newItem)                            throw(ListException){   bool found;   int newPosition = locatePosition(newItem, found);   insert(newPosition, newItem);}  // end sortedInsertvoid SortedList::sortedRemove(ListItemType anItem)                            throw(ListException){   bool found;   int position = locatePosition(anItem, found);   if (found) // item actually found      remove(position);   else      throw ListException(         "ListException: Item to remove not found");}  // end sortedRemoveint SortedList::locatePosition(ListItemType anItem,                               bool& isPresent){     ListNode *trav = getHead();   int position = 1;   while ((trav != NULL) && (getNodeItem(trav) < anItem))   {      trav = getNextNode(trav);      position++;   }  // end while   if ((trav != NULL) && (anItem == getNodeItem(trav)))      isPresent = true;   else      isPresent = false;   return position;}  // end locatePosition

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?