大家帮忙找下问题
程序代码:
文件名为CircList.h template<class T> struct CircLinkNode{ T data; CircLinkNode<T>*link; CircLinkNode(CircLinkNode<T>*next==NULL) {link=next;} CircLinkNode(T d,CircLinkNode<T>*next=null) {data=d;link=next;} }; template<class T> class CircList/*:public LinearList<T>*/{ public: CircList(){first=new CircLinkNode<T>;} /*CircList(CricList<T>&L);*/ ~CircList(){makeEmpty();} void makeEmpty(); int Length()const; bool IsEmpty(){return first->link==first?true:false;} /*CirLinkNode<T>*getHead()const; void setHead(CircLinkNode<T>*p);*/ CircLinkNode<T>*Search(T x); CircLinkNode<T>*Locate(int i); T*getData(int i); void setData(int i,T&x); bool Insert(int i,T x); bool Remove(int i,T&x); /*void input();*/ void output(); private: CircLinkNode<T>*first,*last; }; template<class T> void CircList<T>::makeEmpty(){ CircLinkNode<T>*q; while(first->link!=NULL){ q=first->link; first->link=q->link; delete q; } }; template<class T> int CircList<T>::Length()const{ CircLinkNode<T>*p=first->link;int count=0; while(p!=NULL) {p=p->link;count++;} return count; }; template<class T> CircLinkNode<T>*CircList<T>::Search(T x){ CircLinkNode<T>*current=first->link; while(current!=NULL){ if(current->data==x)break; else current=current->link; } return current; }; template<class T> CircLinkNode<T>*CircList<T>::Locate(int i){ if(i<0)return NULL; CircLinkNode<T>*current=first;int k=0; while(current!=NULL&&k<i){ current=current->link;k++; } return current; }; template <class T> T*CircList<T>::getData(int i){ return (i<0||i>last?NULL:Locate(i)->data); }; template <class T> void CircList<T>::setData(int i,T&x){ if(i<=0)return; CircLinkNode<T>*current=Locate(i); if(current==NULL)return; else{ current->data=x;} }; template <class T> bool CircList<T>::Insert(int i,T x){ CircLinkNode<T>*current=Locate(i); if(current==NULL)return false; CircLinkNode<T>*newNode=new CircLinkNode<T>(x); if(newNode==NULL){cerr<<"存储分配错误!"<<endl;exit(1);}//需要什么头文件? newNode->link=current->link; current->link=newNode; return true; }; template <class T> bool CircList<T>::Remove(int i,T&x){ CircLinkNode<T>*current=Locate(i-1); if(current==NULL||current->link==NULL)return false; CircLinkNode<T>*del=current->link; current->link=del->link; x=del->data; delete del; return true; }; template <class T> void CircList<T>::output(){ CircLinkNode<T>*current=first->link; while(current!=NULL){ cout<<current->data<<endl; current=current->link; } }; /*template <class T> void CircList<T>::input(){ CircLinkNode<T>*current=first->link; while(current!=NULL){ cin>>current->data; current=current->link; } };*/ 主程序: // 2.cpp : Defines the entry point for the console application. /* 1、 定义单循环链表类,实现单循环链表的基本运算:初始化、插入、删除、求表的长度、判空、释放。 本实验的主要目的在于帮助学生熟练掌握线性表的基本操作在链式存储结构上的实现;同时为瑟夫环问题做准备。 (1)初始化单循环链表L (2)从标准输入(键盘)逐个数据输入a,b,c,d,e元素 ,建立单循环链表 (3)输出单循环链表L (4)输出单循环链表L的长度 (5)判断单循环链表L是否为空 (6)输出单循环链表L的第3个元素 (7)输出元素a的位置 (8)在第4个元素位置上插入'f'元素 (9)输出单循环链表L (10)删除L的第3个元素 (11)输出单循环链表L (12)释放单循环链表L */ #include "stdafx.h" #include <iostream.h> #include"CircList.h" /*template<class T>*/ int main(int argc, char* argv[]) { int n; CircList<char> clist; clist.Insert(1,'a'); clist.Insert(2,'b'); clist.Insert(3,'c'); clist.Insert(4,'d'); cout<<"您输入的是:"<<endl;clist.output();cout<<endl; cout<<"表的长度为:"<<clist.Length()<<endl; cout<<"表是空的吗?"<<clist.IsEmpty()<<endl; cout<<"请输入取出表L的元素位置:"<<endl;cin>>n;cout<<clist.getData(n)<<endl; cout<<"a的位置为:"<<clist.Search('a')<<endl; cout<<"在第4个元素位置上插入'f'元素"<<endl;clist.Insert(4,'f'); cout<<"此时的L为:"<<endl;clist.output(); cout<<"删除L的第3个元素"<<endl;clist.Remove(3); cout<<"此时的L为:"<<endl;clist.output(); cout<<"释放单循环链表L"<<endl;clist.makeEmpty(); cout<<"此时的L为:"<<endl;clist.output(); return 0; };这些都是错误不知道该怎么改了:
d:\c++\2\circlist.h(5) : error C2629: unexpected 'struct CircLinkNode<T> ('
d:\c++\2\circlist.h(9) : see reference to class template instantiation 'CircLinkNode<T>' being compiled
d:\c++\2\circlist.h(5) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
d:\c++\2\circlist.h(9) : see reference to class template instantiation 'CircLinkNode<T>' being compiled
d:\c++\2\circlist.h(5) : error C2629: unexpected 'struct CircLinkNode<char> ('
D:\C++\2\2.cpp(35) : see reference to class template instantiation 'CircLinkNode<char>' being compiled
d:\c++\2\circlist.h(5) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
D:\C++\2\2.cpp(35) : see reference to class template instantiation 'CircLinkNode<char>' being compiled
D:\C++\2\2.cpp(38) : error C2660: 'Remove' : function does not take 1 parameters