双链表的建立

来源:互联网 发布:知乎精华 编辑:程序博客网 时间:2024/05/24 11:13
#include<iostream>
using namespace std;
struct Node
{
int data;
Node * pre;
Node* Next;
}
Node *Creat()
{
Node * head;
head->pre = NULL;
head->data = NULL;
Node* p = head;
Node* q = head;
Node* stNode;
bool circle = true;
int x;
while(circle)
{
cin>>x;
if(0 != x)
{
stNode = (Node*)malloc(sizeof(Node));
stNode->data = x;
p->data = stNode;
p->pre = q;
q = p;
p =p->Next;
}
circle = 0;
}
p->Next = NULL;
return head;
}
0 0