数据结构单链表的C++实现:
//公元2013年3月17日
//Single List--By Paul
#ifndef _SingleList_
#define _SingleList_
#include
using namespace std;
template
//结点类。。。
template
private:
Type data;
ListNode *pnext;
private:
friend typename SingleList
ListNode():pnext(null){}
ListNode(const Type item,ListNode
~ListNode()
{
pnext=null;
}
public:
Type GetData();
friend ostream& operator<<
};
template
{
return this->data;
}
template
{
os<
}
//单链表类
template
{
private:
ListNode
public:
SingleList():head(new ListNode
~SingleList()
{
MakeEmpty();
delete head;
}
//其他的功能函数
void MakeEmpty();
int Length();
ListNode
ListNode
bool Insert(Type item,int n=0);
Type Remove(int n=0);
bool RemoveAll(Type item);
Type Get(int n);
void Print();
};
//功能函数的实现
template
{
ListNode
while(head->pnext!=null)
{
pdel=head->pnext;
head->pnext=pdel->pext;
delete pdel;
}
}
template
{
ListNode
int count=0;
while(pmove!=null)
{
pmove=pmove->pnext;
count++;
}
return count;
}
template
{
if(n<0)
{
cout<<"The N is out of boundry"<
}
ListNode
for(int i=0;i
pmove=pmove->pnext;
}
if(pmove==null)
{
cout<<"The N is out of boundary"<
}
}
template
if(n<1){
cout<<"The n is illegal"<
}
ListNode
int count=0;
while(count!=n&&pmove){
pmove=pmove->pnext;
if(pmove->data==value){
count++;
}
}
if(pmove==NULL){
cout<<"can't find the element"<
}
return pmove;
}
template
if(n<0){
cout<<"The n is illegal"<
}
ListNode
ListNode
if(pnode==NULL){
cout<<"Application error!"<
}
for(int i=0;i
}
if(pmove==null){
cout<<"the n is illegal"<
}
pnode->pnext=pmove->pnext;
pmove->pnext=pnode;
return 1;
}
#endif
//公元2013年3月17日
//Single List--By Paul
#ifndef _SingleList_
#define _SingleList_
#include
using namespace std;
template
//结点类。。。
template
private:
Type data;
ListNode *pnext;
private:
friend typename SingleList
ListNode():pnext(null){}
ListNode(const Type item,ListNode
~ListNode()
{
pnext=null;
}
public:
Type GetData();
friend ostream& operator<<
};
template
{
return this->data;
}
template
{
os<
}
//单链表类
template
{
private:
ListNode
public:
SingleList():head(new ListNode
~SingleList()
{
MakeEmpty();
delete head;
}
//其他的功能函数
void MakeEmpty();
int Length();
ListNode