建立双链表

来源:互联网 发布:小说小偷源码 编辑:程序博客网 时间:2024/06/05 01:15
#include <iostream>typedef struct student{int data;struct student *next;struct student *pre;}dnode;// 建立双链表dnode *creat(){dnode *head, *p, *s;int x, cycle = 1;head = (dnode *)malloc(sizeof(dnode));p = head;while(cycle){printf("Please input the data!\n");scanf("%d", x);if(x != 0){s = (dnode *)malloc(sizeof(dnode));s->data = x;printf("%d\n", s->data);p->next = s;s->pre = p;p = s;}else cycle = 0;}//head = head->next;head->pre = NULL;p->next = NULL;//printf("head->data = %d", head->data);return head;}

0 0
原创粉丝点击