这是用C++写的数组线性表的插入函数,其中第二个if条件中,如果用 listSize+1 是没有问题的,如果用 listSize++ 程序执行是有错误的(非编译错误)
void insert(int location, elementtype theElement)
{ if(location > arrayLength - 1) cout<<"List is full."<<endl; if(location > (listSize+1) || location < 1 ) cout<<"Please enter correct value."<<endl; else
{ for(int n = listSize; n >= location; n--)
elements[n++] = elements[n];
elements[location] = theElement;
listSize++;
}
}i++和i+1在比较运算符中有什么区别吗?
缥缈止盈
相关分类