insert.cpp

来自「Data Abstraction & Problem Solving with 」· C++ 代码 · 共 22 行

CPP
22
字号
#include "ListAexcept.h"void List::insert(int index, ListItemType newItem)                  throw(ListIndexOutOfRangeException, ListException){   if (size >= MAX_LIST)      throw ListException("ListException: List full on insert");   if (index >= 1 && 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   }   else  // index out of range      throw ListIndexOutOfRangeException(       "ListIndexOutOfRangeException: Bad index on insert");   // end if} // end insert

⌨️ 快捷键说明

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