建设部监理资质查询:链表 双向链表

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/20 17:12:56
#include<iostream.h>
#include<malloc.h>
#define LEN sizeof(struct student)
#define NULL 0

int count=0;
struct student{
int num;
struct student *before;
struct student *next;
};

struct student *tail; //define the tail point.

struct student *creat(void){
struct student *head=NULL;
struct student *p1=NULL;
struct student *p2=NULL;
int n;
head=p1=p2=(struct student *)malloc(LEN);
head->before =NULL;
head->next =NULL;// initial
tail=head;

cout<<" pleast enter the data(enter 0 to exit): ";
cin>>n;

while(n!=0){
count++;
cout<<"please enter the "<<count+1<<" Node: ";
p2=(struct student * )malloc(LEN);
tail=p2; //set the tail point .
p2->before =p1;
p1->next =p2;
p2->next =NULL;

p1->num=n;
p1=p1->next;
cin>>n;
}

tail->next =NULL;
cout<<"the DNode created."<<endl;
return(head);
}
在创立后,HEAD指针正常,但尾指针tail指向不正常。请都问题出
在哪。。。。