双向链表,大家来帮我一下。我改不了了。

来源:百度知道 编辑:UC知道 时间:2024/06/22 02:10:35
#include<stdio.h>
#include<stdlib.h>

typedef struct sNode
{
int date;
struct sNode *next;
struct sNode *back;
}Node;

Node *creat()
{
Node *head;
head=(Node *)malloc(sizeof(Node));
head->next=NULL;
head->back=NULL;
}

Node *input(Node *head,Node *newNode)
{
Node *s,*q;
s=head->next;
q=newNode;
//printf("1");
if(s==NULL)
{
head->next=q;
q->back=head;
head->back=NULL;
q->next=NULL;
}
else
{
while(s)
{
if(s->next==NULL)
{
s->next=q;
q->back=s;
}
s=s->next;
}
}
return head;
}

void print(Node *head)
{
Node *p;
int i;
p=head->next;
printf("正序1反序2:");
scanf("%d",&i);
if(i==1)
{
while(p)

修改如下(反向输出的问题已经修正):

//---------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>

typedef struct sNode
{
int date;
struct sNode *next;
struct sNode *back;
}Node;

Node *creat(void)
{
Node *head;
head=(Node *)malloc(sizeof(Node));
head->next=NULL;
head->back=NULL;
return head; /*注意这里*/
}

Node *input(Node *head,Node *newNode)
{
Node *s,*q;
s=head->next;
q=newNode;
//printf("1");
if(s==NULL)
{
head->next=q;
q->back=head;
head->back=NULL;
q->next=NULL;
}
else
{
while(s->next) /*注意这里*/
{
s=s->next; /*注意这里*/
}
if(s->next==NULL) /*注意这里*/
{
s->next=q;
q->back=s;
}
}
return head;
}