创建双链表

来源:互联网 发布:网络图片搞笑 编辑:程序博客网 时间:2024/05/21 15:05
#include <iostream>using namespace std;struct node{int data;node* first;node* second;};node* Creat(){node* head,*p1,*p2;int m,n;cout<<"please input your data"<<endl;head=(node*)malloc(sizeof(node));if(cin>>m)head->data=m;else{cout<<"wrong"<<endl;return NULL;}head->first=NULL;p1=head;while(cin>>n){p2=(node*)malloc(sizeof(node));p2->data=n;p2->first=p1;p1->second=p2;p1=p2;}p1->second=NULL;return head;}

0 0
原创粉丝点击