设为首页 加入收藏

TOP

单链表的简单c++实现
2015-11-21 00:58:53 来源: 作者: 【 】 浏览:2
Tags:单链表 简单 实现

以下代码只实现了单链表的手动创建以及输出功能

#include
   
     using namespace std; struct node { int data; node *next; }; class list { public: void creat(); void show(); private: node *head; }; void list::creat() //创建链表 { node *f=new node(); //建立链表的第一个元素 f->data=44; f->next=NULL; head=f; f=new node(); //建立链表的第二个元素 f->data=72; f->next=NULL; head->next=f; f=new node(); //建立链表的第三个元素 f->data=220; f->next=NULL; head->next->next=f; } void list::show() //输出链表 { node *p=head; while(p->next) { cout<
    
     data<<"->"; p=p->next; } cout<
     
      data<
      
     
    
   
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇c++处理矩阵操作:Eigen库初步学.. 下一篇POJ 3107 Godfather (树的重心)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: