|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream>
using namespace std;
typedef struct {
int data;
struct node *next;
}Lnode,*pList;//第二个是指向结点结构的指针。
class list{
public:
list();//构造函数
int length();//求链表长度。
~list();//析构函数。
private:
Lnode *head; //头结点。
};
//定义构造函数.
list::list(){
Lnode *head=new Lnode;
head->next=NULL; //将头结点下一个地址指向空。
}
//定义求表长函数.
int list::length(){
Lnode*p=head->next;
int n=0;
if(p=NULL){
cout<<"表为空"<<endl;
return 0;
}
else {
while(p!=NULL){
p=p->next;
n++;
}
return n;
}
}
int main(){
list L;
L.length();
L.~list;
return 0;
} |
|