本文整理汇总了C++中SeqList::InsertElem方法的典型用法代码示例。如果您正苦于以下问题:C++ SeqList::InsertElem方法的具体用法?C++ SeqList::InsertElem怎么用?C++ SeqList::InsertElem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SeqList
的用法示例。
在下文中一共展示了SeqList::InsertElem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, const char * argv[]) {
char c='*';
SeqList<int> *la = new SeqList<int>(6);
int e = 0, i = 0;
Status status;
while (c != '0') {
cout << endl << "1. 生成线性表.";
cout << endl << "2. 显示线性表.";
cout << endl << "3. 取指定元素.";
cout << endl << "4. 设置元素值.";
cout << endl << "5. 删除元素.";
cout << endl << "6. 插入元素.";
cout << endl << "7. 元素定位.";
cout << endl << "8. 求线性表长度.";
cout << endl << "0. 退出";
cout << endl << "选择功能(0~8):";
cin >> c;
switch (c) {
case '1':
{
la->Clear();
status = SUCCESS;
cout << endl << "输入e( e = 0时退出):";
cin >> e;
while (e != 0 && status != OVER_FLOW) {
status = la->InsertTailElem(e);
if (status == OVER_FLOW) {
cout << "线性表已满。" << endl;
}else {
cin >> e;
}
}
}
break;
case '2':
{
la->Traverse(Write<int>);
//system("clear");
}
break;
case '3':
{
cout << endl << "输入元素位置:";
cin >> i;
if (la->GetElem(i, e) == NOT_PRESENT) {
cout << "元素不存在" << endl;
}else {
cout << "元素:" << e <<endl;
}
}
break;
case '4':
{
cout<< endl << "输入位置:";
cin >> i;
cout <<endl<<"输入元素值:";
cin >> e;
if (la->SetElem(i, e) == RANGE_ERROR) {
cout<<"位置范围错误"<<endl;
}else {
cout<<"设置成功"<<endl;
}
}
break;
case '5':
{
cout << endl << "输入位置:";
cin >> i;
if (la->DeleteElem(i, e) == RANGE_ERROR) {
cout << "位置范围错." << endl;
}else {
cout << "被删除元素值:" << e << endl;
}
}
break;
case '6':
{
cout << endl << "输入位置:";
cin >> i;
cout << endl << "输入元素值:";
cin >> e;
status = la->InsertElem(i, e);
if (status == RANGE_ERROR) {
cout << "位置范围错." << endl;
} else if (status == OVER_FLOW) {
cout << "线性表已满." << endl;
}else {
cout << "插入成功." << endl;
//.........这里部分代码省略.........