单链表的简单c++实现

来源:互联网 发布:手机照片调色软件 编辑:程序博客网 时间:2024/06/05 20:31

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

#include<iostream>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<<p->data<<"->";    p=p->next;  }  cout<<p->data<<endl;}int main(){ list L1; L1.creat(); L1.show(); system("pause"); return 0;}
0 0
原创粉丝点击