关于格雷码的c语言实现
程序代码:#include <stdio.h>
#include<malloc.h>
#define len sizeof(struct Dulnode)
#define null 0
typedef struct Dulnode{
int e;
struct Dulnode *next;
struct Dulnode *front;
} Dulist;//定义一个结构体,代表双向链表的节点;
int i;
struct Dulnode *creat(void) // 建立一个双向链表;
{
struct Dulnode *head;
struct Dulnode *p1,*p2;
head=null;
i=0;
p1=p2=(struct Dulnode*)malloc(len);
scanf_s("%d",&p1->e);
head=null;
while(p1->e==0||p1->e==1)
{
i=i+1;
if(i==1)head=p1;
else {
p2->next=p1;
p1->front=p2;
};
p2=p1;
p1=(struct Dulnode*)malloc(len);
scanf("%d",&p1->e);
}
p2->next=null;
return head;
}
struct Dulnode * Gray(struct Dulnode *head)//二进制码转化为格雷码;
{
int j;
struct Dulnode *q1;
head=creat();
q1=head;
for(j=0;j<=i;j++)
q1=q1->next;
while(q1->e==0||q1->e==1)
{
if(q1->e==(q1->front)->e)
(q1->front)->e=0;
else (q1->front)->e=1;
q1=q1->front;
}
head=q1;
return(head);
}
void print(struct Dulnode *head)//输出一行二进制码;;
{
struct Dulnode *p;
printf("格雷码的序列:\n");
p=head;
if(head!=null)
do
{
printf("%d",p->e);
p=p->next;
}while(p!=null);
}
void main()
{
struct Dulnode *head;
printf("请输入二进制码:");
head=creat();
printf("转化为格雷码:");
head=Gray(head);
print(head);
}在调试的时候,出现下图所示的错误,请问是怎么回事?







