【文件属性】:
文件名称:单链表倒数第节点
文件大小:2KB
文件格式:TXT
更新时间:2017-10-30 13:54:23
数据结构
# include
using namespace std;
template
struct Node
{
T data;
Node *next;
};
template
class LinkList
{
public:
LinkList();
LinkList(T a[],int n);
int length();
void display();
void searchNode(int k);
private:
Node*first;
};
template
LinkList::LinkList(T a[],int n)
{
Node *s;
//Node *date;
first=new Node;
first->next=NULL;
for(int i=0;i;
s->data=a[i];
s->next=first->next;
first->next=s;
}
}
template
int LinkList::length()
{
Node *p;
int count=0;
p=first->next;
while(p!=NULL)
{
p=p->next;
count++;
}
return count;
}
template
void LinkList::display()
{
Node *p;
p=first->next;
while(p!=NULL)
{
cout<data<<" ";
p=p->next;
}
cout<
void LinkList::searchNode(int k)
{
Node *big,*little;
big=first->next;
little=first->next;
for(int i=1;inext!=NULL)
big=big->next;
}
while(big->next!=NULL)
{
big=big->next;
little=little->next;
}
cout<<"倒数第"<data<>length;
for(int i=0;i list(a,length);
cout<<"单链表为:"<