//链表:它有设计为大小合适的容器组成,容器根据需要连接起来
//链表组件:链表有节点组成,每个节点可放置指定的数据类型
//head node //头结点:管理链表的头
//尾节点 初始化时,头结点指向尾节点
//内部节点:存放数据类型
//head pointer 用来指向头结点的指针
/*
typedef int T ; //将int 类型用T来表示
struct Node{ //简单的节点内容
int date;
Note *next;//注意指针的类型,为结构体类型
};(可将节点设置为内部类和外部类)
*/
include <iostream>
using namespace std;
typedef int T;
void test1()
{
struct Node{
T date;
Node* next;
};
Node n1;
Node* p = new Node;
cout << "n1.date = " << n1.date << endl;//未声明式,存放垃圾数据
cout << "n1.next = " << n1.next << endl;
cout << "p->date = " << p->date << endl;
cout << "p->next = " << p->next << endl;
}
void test2()
{
struct Node{
T date;
Node* next;
Node(const T& d =T() ): date(d),next(NULL){}
};
//结构体也可以用构造函数无名对象创造新对象时,编译器会优化数据
Node n1;
Node* p = new Node;
cout << "n1.date = " << n1.date << endl;//未声明式,存放垃圾数据
cout << "n1.next = " << n1.next << endl;
cout << "p->date = " << p->date << endl;
cout << "p->next = " << p->next << endl;
}
int main(int argc, char const *argv[])
{
test1();
test2();
return 0;
}