操作函数:clear(清除表)、traverse(正序输出)、search(搜索表)、insert(插入)、remove(删除)、inverse(倒序输出)、resize(修改)、visit(查看)。
int curlength =4,maxSize=6;
1、clear函数——clear()
curlength=0;
2、traverse函数——traverse()
if(empty())
cout << "squence list is empty;
else
{
cout << "result:";
for(int i;i < curlength;++i)
cout << data[i] << ' ';
cout << endl;
}
3、search函数——search(value)
for(int i=0;i
4、insert函数——insert(i,value)
if(i<0||i>curlength)
throw outOfRange();
if(curlength==maxSize)
resize();
for(int j=curlength;j>i;--j)
data[j]=data[j-1];
data[i]=value;
++curlength;
5、remove函数——remove(i)
if(i<0||i>curlength)
throw outOFRange();
for(j=i;j
6、inverse函数——inverse()
elemType tmp;
for(int i=0;i
7、resize函数——resize()
elemType *p=data;
maxSize *=2;
data=new elemType[maxSize];
for(int i=0;i
8、visit函数——visit(i)
if(i<0||i>curlength)
throw outOfRange();
return data[i];
操作函数:clear(清除表)、traverse(正序输出)、search(搜索表)、insert(插入)、remove(删除)、inverse(倒序输出)、getposition(返回第i+1个元素)、visit(查看)。
1、clear函数——clear()
Node *p,*tmp;
p=head->next;
while(p!=NULL)
{
tmp=p;
p=p->next;
delete tmp;
}
head->next=NULL;
tail=head;
curlength=0;
2、traverse函数——traverse()
Node *p=head->next;
cout << "result:";
while(p!=NULL)
{
cout << p->data << ' ';
p=p->next;
}
cout << endl;
3、getposition函数——getposition(i)
if(i<-1||i>curlength-1)
return NULL;
Node *p=head;
int count=0;
while(count<=i)
{
p=p->next;
count++;
}
return p;
4、search函数——search(value)
Node *p=head->next;
int count=0;
while(p!=NULL&&p->data!=value)
{
p=p->next;
++count;
}
if(p==NULL)
return -1;
else
return count;
5、insert函数——insert(i,value)
Node *p,*q;
if(i<0||i>curlength)
throw outOfRange();
p=getposition(i-1);
q=new Node(value,p-next);
p->next=q;
if(p==tail)
tail=q;
++curlength;
6、remove函数——remove(i)
Node *pre,*p;
if(i<0||i>curlength-1)
throw outOfRange();
pre=getposition(i-1);
p=pre->next;
if(p==tail)
{
tail=p;
pre->next=NULL;
delete p;
}
else
{
pre->next=p->next;
delete p;
}
--curlength;
7、inverse函数——inverse()
Node *p,*tmp;
p=head->next;
head->next=NULL;
if(p!=NULL)
tail=p;
while(p!=NULL)
{
tmp=p->next;
p->next=head->next;
p=tmp;
}
8、visit函数——visit(i)
Node *p=head->next;
int count=0;
if(i<0||i>curlength-1)
throw outOfRange();
while(countnext;
++count;
}
return p->data;