编译:VS2017
语言:C
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#pragma warning(disable:4996)
typedef struct Node {
int data;
struct Node *pre;
struct Node *next;
}node;
int main()
{
node *head,*p;
int i;
head = (node *)malloc(sizeof(node));
head->data = 0;
head->pre = NULL;
printf("enter numbers 0 exit\n");
scanf("%d", &i);
p = (node *)malloc(sizeof(node));
p->data = i;
p->next = NULL;
head->next = p;
p->pre = head;
scanf("%d", &i);
while (i != 0)
{
p = (node *)malloc(sizeof(node));
p->data = i;
p->next = head->next;
head->next->pre = p;
head->next = p;
p->pre = head;
scanf("%d", &i);
}
p = head->next;
while (p)
{
printf("%d\n", p->data);
p = p->next;
}
return 0;
}