主题:怎样才能把结果的双向表输出来!?
#include<stdio.h>
#include"stdlib.h"
#define TRUE 1
#define FALSE 0
typedef struct DNode
{
int a;
struct DNode *prior;
struct DNode *next;
}DNode,*DoubleList;
InitList(DoubleList *L) [color=00FF00] //*初始化[/color]
{
*L=(DoubleList)malloc(sizeof(DNode));
(*L)->next=(*L);
(*L)->prior=(*L);
}
void CreateFromTail(DoubleList L) [color=00FF00]//*给与赋值[/color]
{
DNode *r,*s;
int flag=1;
int b;
r=L;
printf("建立双向表\n");
while(flag)
{
scanf("%d",&b);
if(b!=0)
{
s=(DNode *)malloc(sizeof(DNode));
s->a=b;
r->next=s;
s->prior=r;
r=s;
}
else
{
flag=0;
r->next=L;
}
}
}
int DLinkList(DoubleList L,int i,int b) //*插入
{
DNode *s,*p;
int j;
p=L;
if(i<0)
printf("ERROR");
for(j=0;j<i;j++)
{
if((p->next!=L)&&(p->prior!=L))
p=p->next;
}
s=(DNode *)malloc(sizeof(DNode));
if(s)
{
s->a=b;
s->prior=p->prior;
p->prior->next=s;
s->next=p;
p->prior=s;
return TRUE;
}
else return FALSE;
}
void main()
{
DoubleList L;
InitList(&L);
CreateFromTail(L);
int i,b;
printf("插入的位置i,插入的值b\n");
scanf("%d,%d",&i,&b);
DLinkList(L,i,b);
DNode *r;
r=L->next;
printf("输出双向表\n");
while(r!=L)
{
printf("%d ",r->a);
r=r->next;
}
free(L);
}
但是结果输出来怎么只有插入的值啊!?
哪位帮忙说说啊!?
最好把头指针,尾指针等讲详细点,谢了
#include"stdlib.h"
#define TRUE 1
#define FALSE 0
typedef struct DNode
{
int a;
struct DNode *prior;
struct DNode *next;
}DNode,*DoubleList;
InitList(DoubleList *L) [color=00FF00] //*初始化[/color]
{
*L=(DoubleList)malloc(sizeof(DNode));
(*L)->next=(*L);
(*L)->prior=(*L);
}
void CreateFromTail(DoubleList L) [color=00FF00]//*给与赋值[/color]
{
DNode *r,*s;
int flag=1;
int b;
r=L;
printf("建立双向表\n");
while(flag)
{
scanf("%d",&b);
if(b!=0)
{
s=(DNode *)malloc(sizeof(DNode));
s->a=b;
r->next=s;
s->prior=r;
r=s;
}
else
{
flag=0;
r->next=L;
}
}
}
int DLinkList(DoubleList L,int i,int b) //*插入
{
DNode *s,*p;
int j;
p=L;
if(i<0)
printf("ERROR");
for(j=0;j<i;j++)
{
if((p->next!=L)&&(p->prior!=L))
p=p->next;
}
s=(DNode *)malloc(sizeof(DNode));
if(s)
{
s->a=b;
s->prior=p->prior;
p->prior->next=s;
s->next=p;
p->prior=s;
return TRUE;
}
else return FALSE;
}
void main()
{
DoubleList L;
InitList(&L);
CreateFromTail(L);
int i,b;
printf("插入的位置i,插入的值b\n");
scanf("%d,%d",&i,&b);
DLinkList(L,i,b);
DNode *r;
r=L->next;
printf("输出双向表\n");
while(r!=L)
{
printf("%d ",r->a);
r=r->next;
}
free(L);
}
但是结果输出来怎么只有插入的值啊!?
哪位帮忙说说啊!?
最好把头指针,尾指针等讲详细点,谢了