老是提示缺括号 怎么也着不到
#include<iostream>using namespace std;
typedef int T;
class list{
struct node{
T data;
node* next;
node(const T& d):data(d),next(NULL)
{}
};
int len;
node* head;
public:
list():len(0),head(NULL){}
~list()
{
clear();
}
void clear()
{
while (head!=NULL)
{
node* p=head->next;
delete head;
head=p;
}
len=0;
}
void insert(const T& d,int pos=0)
{
node* p= new node(d);
node *&pn=getpn(pos);
p->next=pn;
pn=p;
len++;
}
node* & getpn(int pos)
{
node* pt=head;
for(int i=0;i<pos-1;i++)
return pt->next;
}
int size()
{
return len;
}
void travel()
{
node*pt=head;
while(pt!=NULL)
{
cout<<pt->data<<' ';
pt=pt->next;
}
cout<<endl;
};
int main()
{
list o1;
char cmd;
T data;
int pos;
for(;;)
{
cout<<"I/L/C/S/P :";
cin>>cmd;
if(cmd=='q')
break;
switch(cmd){
case 'l' :
o1.travel();
break;
case 'c' :
o1.clear();
break;
case 'i' :
cin>>data>>pos;
o1.insert(data,pos);
break;
case 's' :
cout<<o1.size()<<endl;
}
}
return 0;
}
~
QUOTE:
QUOTE:
QUOTE:
QUOTE:
QUOTE: