链表c++实现一
#include <iostream>
using namespace std;
typedef char nodeEntry;
struct Node{
//數據成員
nodeEntry data;
Node* next;
//構建函數
Node();
Node(nodeEntry item,Node* link = NULL);
};
Node::Node()
{
next = NULL;
}
Node::Node(nodeEntry item,Node* link)
{
data = item;
next = link;
}
int main()
{
Node first_node('a'); //構建一個數據項為字符a的節點
Node *p0 = &first_node;//定義一個指向節點first_node('a')的指針p0
Node *p1 = new Node('b');//構建一個數據項為字符b的節點,由指針p1指向該節點
p0->next = p1;//將后面建立的節點掛在第1個創立的節點后面
Node *p2 = new Node('c',p0);//構建第2個節點,數據項為字符c,指針指向第1個節點
p1->next = p2;//將第3個節點掛在第2個節點后面,形成一個循環鏈表
cout<<"鏈表里面的元素為:";
while(p0!=NULL){
cout<<p0->data<<",";
p0 = p0->next;
}
return 0;
}
轉載于:https://www.cnblogs.com/changed/p/6142747.html
總結
- 上一篇: 水系图一般在哪里找得到_城市供水系统防护
- 下一篇: 转:VC中MessageBox的常见用法