level 1
187364503
楼主
#include<iostream>
using namespace std;
template<class Type> class List
{
public:
List()
{
first=new LinkNode<Type>;
}
List(const Type& x)
{
first=new LinkNode<Type>(x);
}
LinkNode<Type>* getHead() const
{
return first;
}
LinkNode<Type>* locate(int i) const
{
if(i<0)
return NULL;
LinkNode *current=first;
int k=0;
while(current!=NULL&&k<i)
{
current=current->link;
k++;
}
return current;
}
private:
class LinkNode
{
public:
Type data;
LinkNode<Type> *link;
LinkNode(LinkNode<Type> *ptr=NULL)
{
link=ptr;
}
LinkNode(const Type& item,LinkNode<Type> *ptr=NULL)
{
data=item;
link=ptr;
}
};
LinkNode<Type> *first;
};
int main()
{
List<int> list;
return 0;
}
2011年11月03日 14点11分
1
using namespace std;
template<class Type> class List
{
public:
List()
{
first=new LinkNode<Type>;
}
List(const Type& x)
{
first=new LinkNode<Type>(x);
}
LinkNode<Type>* getHead() const
{
return first;
}
LinkNode<Type>* locate(int i) const
{
if(i<0)
return NULL;
LinkNode *current=first;
int k=0;
while(current!=NULL&&k<i)
{
current=current->link;
k++;
}
return current;
}
private:
class LinkNode
{
public:
Type data;
LinkNode<Type> *link;
LinkNode(LinkNode<Type> *ptr=NULL)
{
link=ptr;
}
LinkNode(const Type& item,LinkNode<Type> *ptr=NULL)
{
data=item;
link=ptr;
}
};
LinkNode<Type> *first;
};
int main()
{
List<int> list;
return 0;
}