C++的问题(only高手进)

来源:百度知道 编辑:UC知道 时间:2024/05/27 05:58:18
是一个双向链表,用类模板来写
帮我看看什么错误

template<class T>
class List{
public:
void insert(T x,int i); //将x插入到第i个结点
void del(int i); //删除第i个结点
T getlist(int i);
void inputist(); //初始化
private:
struct Node{
Node *next_link; //指针域
Node *pre_link;
T data;
};
Node *first;
};
template<class T>
void List<T>::insert(T x,int i){
Node* newNode,*current,*temp;
newNode=new Node;
if(i==1||first==NULL){
newNode->next_link=first;
first->pre_link=newNode;
first=newNode;
}
current=first;
for(int j=0;j<i-1;j++)
{current=current->next_link;} //current指向要插入的结点前一个结点
temp=current->next_link;
newNode=temp;
temp->pre_link=newNode;
current->next_link=newNode;
newNode->pre_link=current;
return;
};
template<cla

#include <stdio.h>

template<class T>
class List{
public:
List();
void insert(T x,int i); //将x插入到第i个结点
void del(int i); //删除第i个结点
T getlist(int i);
// void inputist(); //初始化
private:
struct Node{
Node *next_link; //指针域
Node *pre_link;
T data;
};
Node *first;
};

template<class T>
List<T>::List()
{
first=NULL;

}

template<class T>
void List<T>::insert(T x,int i){
Node* newNode,*current,*temp;
newNode=new Node;
newNode->data=x;
if(i==1 && first!=NULL){
newNode->next_link=first;
first->pre_link=newNode;
first=newNode;
} else if (i==1)
{
newNode->next_link=first;
first=newNode;
}else
{
current=first;
for(int j=0;j<i-1;j++)
{current=current->next_link;} //cu