Joker_Jay 2017-09-17 02:40 采纳率: 100%
浏览 958
已采纳

按照书上打的,为什么会出现这个问题?求大神帮帮忙

![图片说明图片说明

#include
using namespace std;
#include"process.h"
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);
T GetElem(int i);
int Locate(T e);
void Clear();
int Empty();
int Full;
int Length;
void ListDisp();
};
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::CreatList(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)throw"上溢";
if (ilength + 1)throw"插入位置异常";
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 throw"删除位置异常";
x = elem[i - 1];
for (int j = i; j < length; j++)
elem[j - 1] = elem[j];
length--;
return x;
}
template
int SqList::Locate(T e)
{
for (int i = 0; i < length; i++)
if (elem[i] == e)
return i + 1;
return 0;
}
template
void SqList::GetElem(int i)
{
T e;
if (i <= 1 || i>length)throw"位置不合法";
e = elem[i - 1];
return e;
}
template
int SqList::Full()
{
if (length == listsize)
return 1;
else
return 0;
}
template
int SqList::ListDisp()
{
for (int i = 0; i < length; i++)
{
cout << i + 1 << "\t";
cout << elem[i] << eldl;
}
}
char pause;
typedef int T;
int main()
{
int i;
T e;
SqListL(20);
system("cls");
int choice;
do
{
cout << "1-创建顺序表\n";
cout << "2-在链表的第i位置插入元素\n";
cout << "3-删除顺序表中第i个位置的元素\n";
cout << "4-返回第i个元素的值\n";
cout << "5-元素定位\n";
cout << "6-清空表\n";
cout << "7-测表空\n";
cout << "8-测表满\n";
cout << "9-测表长\n";
cout << "10-显示表\n";
cout << "11-退出\n";
cout << "Enter choice:";
cin >> choice;
switch (choice)
{
case 1:
cout << "请输入要创建的顺序表中的个数:";
cin >> i;
cout << endl;
try
L.CreatList(i);

        catch (char*err)
            cout << err << endl;
        break;
    case 2:
        cout << "请输入插入的位置:";
        cin >> i;
        cout << endl;
        cout << "请输入插入元素的值:";
        cin >> e;
        cout << endl;
        try
            L.Insert(i, e);
        catch (char*err)
            cout << err << endl;
        break;
    case 3:
        cout << "请输入删除的位置:";
        cin >> i;
        cout << endl;
        try
        {
            e = L.Delete(i);
            cout << "被删除的元素为:" << e << endl;
        }
        catch (char*err)
        {
            cout << err << endl;
        }
        cin.get(pause);
        system("pause");
        break;
    case 4:
        cout << "请输入要查询的元素的位置:";
        cin >> i;
        try
        {
            e = L.GetElem(i);
            cout << "第" << i << "个元素值为:" << e << endl;
        }
        catch (char*err)
        {
            cout << err << endl;
        }
        cin.get(pause);
        system("pause");
        break;
    case 5:
        cout << "请输入要查询的元素的值:";
        cin >> e;
        i = L.Locate(e);
        cout << "查询元素" << e << "在于表中的位置为:" << i << endl;
        cin.get(pause);
        system("pause");
        break;
    case 6:
        L.Clear();
        cout << "表已清空!" << endl;
        cin.get(pause);
        system("pause");
        break;
    case 7:
        i = L.Empty();
        if (i)
            cout << "表空" << endl;
        else
            cout << "表不空" << endl;
        cin.get(pause);
        system("pause");
        break;
    case 8:
        i = L.Full();
        if (i)
            cout << "表满" << endl;
        else
            cout << "表未满" << endl;
        cin.get(pause);
        system("pause");
        break;
    case 9:
        i = L.Length();
        cout << "表长为:" << i << endl;
        cin.get(pause);
        system("pause");
        break;
    case 10:
        L.ListDisp();
        cout << endl;
        cin.get(pause);
        system("pause");
        break;
    case 11:
        break;
    default:
        cout << "Invalid choice !\n";
        break;
    }
} while (choice != 11);
return 0;

}

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-09-17 02:52
    关注
     大兄弟,程序能照着输入么?这么多代码能输入正确么?
    
    void CreateList(int m);
    
    后面你
    void SqList<T>::CreatList(int)
    少了一个e
    
    elem = [j] = elem[j - 1];
    这里elem[j]写成了[j]
    这种错误还有很多。
    
    建议你还是搞清楚怎么写程序,图书只是参考
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Workbench中材料库无法更新,如何解决?
  • ¥20 如何推断此服务器配置
  • ¥15 关于github的项目怎么在pycharm上面运行
  • ¥15 内存地址视频流转RTMP
  • ¥100 有偿,谁有移远的EC200S固件和最新的Qflsh工具。
  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析
  • ¥15 Chrome Manifest扩展引用Ajax-hook库拦截请求失败