1
1) false
2) 4
3) a,c,给出错误信息
4)0,2,错误信息
5){b,c,d},{a,b,d}.{a,b,c}
6){e,a,b,c,d}
2找不到公式5-1
3:
4
if (listSize == arrayLength) {
changeLengthlD(element, arrayLength, 2 * arrayLength);
arrayLength *= 2;
}
5:
template<typename T> void trimeTosize() {
if (listSize>1) {
int i = listSize;
}
else {
int i = 1;
changeLength1D(element, 0, i);
arrayLength = i; //修改数组容量值
}
}
6:
//使线性表的大小为指定的大小。
void setSize() {
if (listSize > 50) {
T* temp = new T [50];
copy(element, element + 50, temp);
int p = arrayLength;
delete [] element;
element = temp;
arrayLength = p;
}
}
7:
//重载运算符[]
T& operator[](int theIndex) {
return (element[theIndex]);
}
8-10:
重载操作符==,!=,<,>:
//重载运算符==,!=,>,<.
bool friend operator ==(const arraylist<T>& y, const arraylist<T>& x) {
if (x.listSize != y.listSize) {
return 0;
}
else {
for (int i = 0; i != x.listSize; ++i) {
if (x.element[i] != y.element[i]) {
return 0;
}
}
}
return 1;
}
bool friend operator !=(const arraylist<T>& y, const arraylist<T>& x) {
if (x.listSize != y.listSize) {
return 1;
}
else {
for (int i = 0; i != x.listSize; ++i) {
if (x.element[i] != y.element[i]) {
return 1;
}
}
}
return 0;
}
bool friend operator <(const arraylist<T>& x, const arraylist<T>& y)
{
int j = min(x.listSize, y.listSize);
for (int i = 0; i != j; ++i) {
if (x.element[i] != y.element[i]) {
if (x.element[i]>y.element[i]) {
return 0;
}
else
return 1;
}
}
if (x.listSize<y.listSize) {
return 1;
}
else
return 0;
}
bool friend operator >(const arraylist<T>& y, const arraylist<T>& x)
{
int j = min(x.listSize, y.listSize);
for (int i = 0; i != j; ++i) {
if (x.element[i] != y.element[i]) {
if (x.element[i]>y.element[i]) {
return 0;
}
else
return 1;
}
}
if (x.listSize<y.listSize) {
return 1;
}
else
return 0;
}