错误是结构体的定义
'node' : 'struct' type redefinition
大家说说为什么错(vc6.0)
#define YES 1
#define NO 0
typedef int elemtype;
typedef struct node
{
elemtype data;
struct node *next;
struct node *prior;
}*dlink;
/***********************************************/
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include"2-3define.h"
dlink creatdlink(int n)
{
int j;
dlink head,p,s;
p=head=(dlink)malloc(sizeof(dlink));
for(j=0;j<n;j++)
{
s=(dlink)malloc(sizeof(dlink));
printf("Input the %d data:\n",j);
scanf("%d",&s->data);
p->next=s;
s->next=NULL;
s->prior=p;
p=s;
}//P->prior通个p=s来实现
p->next=NULL;
return head;
}
int getlen(dlink head)
{
int j=0;
dlink p;
p=head->next;
while(p!=NULL)
{
j++;
p=p->next;
}
return j;
}
int getelem(dlink head ,int n)
{ dlink q;
int j;
q=head->next;
if(head->next==NULL)
printf("The link is empty !\n");
return NO;
while(q!=NULL&&j<n)
{
q=q->next;
j++;
}
if(q==NULL)
return NO;
else
return q->data;
}
int locate(dlink head ,elemtype x)
{
dlink q;
int j=1;
q=head->next;
if(head->next=NULL)
printf("The link is empty !\n");
while(q!=NULL&&q->data!=x)
{
q=q->next;
j++;
}
if(q==NULL)
return NO;
else
return j;
}
int delete(dlink head ,int q)
{
dlink p,s;
int j;
if(q<1)
printf("wrong input:\n");
return NO;
p=head ;
j=0;
while(p->next!=NULL&&j<q)
{
p=p->next;
j++;
}
if(p->next==NULL)
return NO;
s=p->next;
p->next=s->next;
if(s->next!=NULL)
s->next->prior=p;
free(s);
return YES;
}
int insert(dlink head ,int p,elemtype x)
{
dlink q,s;
int j;
if(p<1)
printf("wrong input:\n");
return NO;
q=head;
j=0;
while (q!=NULL&&j<p-1)
{
q=q->next;
j++;
}
if(q==NULL)
return NO;
s=(dlink)malloc(sizeof(dlink));
s->data=x;
s->next=q->next;
s->prior=q;
if(q->next!=NULL)
q->next->prior=s;
q->next=s;
return YES;
}
void list(dlink head)
{
dlink p;
p=head->next;
while(p!=NULL)
{
printf("%4d",p->next->data);
p=p->next;
}
printf("\n");
while(p!=NULL)
{
printf("%4d",p->data);
p=p->prior;
}
printf("\n");
}
/*******************************************************/
#include<stdio.h>
#include"2-3define.h"
#include"2-3lib.h"
void main()
{
int i;
dlink H;
dlink creatdlink(int n);
void list(dlink head);
i=4;
H=creatdlink(i);
list(H);
}
//随意用的两个函数