Joker_Jay 2017-09-19 03:58 采纳率: 100%
浏览 874
已采纳

就帮忙,一个未遇见过得错误,不知所措ing

#include
using namespace std;
template
class SqList
{
private:
T *elem;
int length;
int listsize;
public:
SqList(int m);
~SqList();
void CreateList(int m);
void Insert(int i, T e);
T Delete(int i);
};
template
SqList::SqList(int m)
{
elem = new T[m];
length = 0;
listsize = m;
}
template
SqList::~SqList()
{
delete[]elem;
length = 0;
listsize = 0;
}
template
void SqList::CreateList(int n)
{
if (n > listsize)throw"参数非法";
cout << "请依次输入" << n << "个元素值:" << endl;
for (int i = 1; i <= n; i++)
cin >> elem[i - 1];
length = n;
}
template
void SqList::Insert(int i, T e)
{
if (length >= listsize)cout << "上溢" << endl;
if (ilength + 1)cout << "插入位置异常" << endl;
for (int j = length; j >= i; j++)
elem[j] = elem[j - 1];
elem[i - 1] = e;
length++;
}
template
T SqList::Delete(int i)
{
T x;
if (length == 0) cout << "删除位置异常" << endl;
x = elem[i - 1];
for (int j = i; j < length; j++)
elem[j - 1] = elem[j];
length--;
return x;
}
typedef int T;
int main()
{
int i;
T e;
SqListL(5);
int choice;
do
{
cout << "1-创建顺序表\n";
cout << "2-在顺序表的第i位置插入元素\n";
cout << "3-删除顺序表中第i个位置的元素\n";
cout << "4-显示表\n";
cout << "5-退出\n";
cout << "Enter choice:";
cin >> choice;
switch (choice)
{
case 1:
cout << "请输入要创建的顺序表中的个数:";
cin >> i;
L.CreateList(i);
cout << endl;
break;
case 2:
cout << "请输入插入的位置:";
cin >> i;
cout << endl;
cout << "请输入插入元素的值:";
cin >> e;
cout << endl;
L.Insert(i,e);
break;

    case 3:
        cout << "请输入删除的位置:";
        cin >> i;
        cout << endl;
        e = L.Delete(i);
        cout << "被删除的元素为:" << e << endl;
        break;
    case 4:
        break;
    default:
        cout << "Invalid choice !\n";
        break;
    }
} while (choice != 4);
return 0;

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-09-19 05:30
    关注
     你的后括号是全角的),改成半角 ) 才行,这种错误有好几个
    
    < = 这里不能有空格,应该是 <=
    
    elem = [j] = elem[j - 1]; 这个你上次就错了,说了你还不改
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器