这是小弟我编的,是不是我的tail没指到表尾?只能正过来输出,不能反过来输出诶,哪位高手能解答下啊?不甚感激!
include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct node{
int data;
struct node *next;
struct node *prior;
}Node,*LinkList;
void CreateList(LinkList *head)
{
LinkList p,q;
int x;
if((*head=(Node *)malloc(sizeof(Node)))==NULL) exit(1);
(*head)->next=(*head)->prior=NULL;
q=(*head);
printf("please input data:\n");
scanf("%d",&x);
do
{
if((p=(Node *)malloc(sizeof(Node)))==NULL) exit(1);
p->data=x;
p->next=NULL;
p->prior=q;
q->next=p;
q=p;
p=NULL;
printf("please input number:\n");
fflush(stdin);
scanf("%d",&x);
}while(x!=0);
}
void print1(LinkList head)
{
LinkList p;
p=head->next;
while(p!=NULL)
{
printf("%d -> ",p->data);
p=p->next;
}
}
void print2(LinkList tail)
{
LinkList p;
p=tail->prior;
while(p!=NULL)
{
printf("%d -> ",p->data);
p=p->prior;
}
}
main()
{ LinkList head,tail;
CreateList(&head);
print1(head);
printf("\n");
print2(tail);
}