| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3111 人关注过本帖
标题:关于格雷码的c语言实现
只看楼主 加入收藏
whw055670
Rank: 2
来 自:云南昆明
等 级:论坛游民
帖 子:12
专家分:10
注 册:2010-10-29
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:2 
关于格雷码的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);

 }
在调试的时候,出现下图所示的错误,请问是怎么回事?
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: c语言 格雷码 
2010-11-25 18:40
whw055670
Rank: 2
来 自:云南昆明
等 级:论坛游民
帖 子:12
专家分:10
注 册:2010-10-29
收藏
得分:0 
我的软件是vs2010 不知道是程序本身有问题还是我的软件有问题,大哥大姐们帮帮忙.

大家合作愉快
2010-11-25 20:18
fightingsss
Rank: 6Rank: 6
等 级:侠之大者
帖 子:97
专家分:471
注 册:2010-11-12
收藏
得分:20 
格雷码,不就是二进制码不断异或运算得到的。。。
2010-11-27 11:46
快速回复:关于格雷码的c语言实现
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015510 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved