网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

c语言gethead函数 C语言head

C语言 数据结构 二叉树层次遍历

#include "stdio.h"

创新互联专注于玉山企业网站建设,自适应网站建设,电子商务商城网站建设。玉山网站建设公司,为玉山等地区提供建站服务。全流程按需设计,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务

#include "stdlib.h"

typedef struct btnode//二叉链表类型定义

{char data;

struct btnode *lchild,*rchild;

}bintree,*Bintree;

typedef struct LinkQueueNode//链队列类型定义

{bintree *data;

struct LinkQueueNode *next;

}LKQueNode;

typedef struct LKQueue

{LKQueNode *front,*rear;

}LKQue;

void InitQueue(LKQue *LQ)//初始化队列

{LKQueNode *p;

p=(LKQueNode*)malloc(sizeof(LKQueNode));

LQ-front=p;

LQ-rear=p;

(LQ-front)-next=NULL;

}

int EmptyQueue(LKQue *LQ)//判断队列是否为空

{if(LQ-front==LQ-rear)

return 1;

else return 0;

}

void EnQueue(LKQue *LQ,Bintree x)//入队列

{LKQueNode *p;

p=(LKQueNode*)malloc(sizeof(LKQueNode));

p-data=x;

p-next=NULL;

(LQ-rear)-next=p;

LQ-rear=p;

}

int OutQueue(LKQue *LQ)//出队列

{LKQueNode *s;

if ( EmptyQueue(LQ))

{exit(0);return 0;}

else

{s=(LQ-front)-next;

(LQ-front)-next=s-next;

if(s-next==NULL)

LQ-rear=LQ-front;

free(s);

return 1;}

}

Bintree GetHead(LKQue *LQ)//取队列首元素

{LKQueNode *p;bintree *q;//q-data=-1; 错误在这里没有分配空间就赋值

if(EmptyQueue(LQ))

return q;

else {p=LQ-front-next;

return p-data;

}

Bintree initiate()//建二叉树 

{char ch;Bintree t;

ch=getchar();    

if(ch=='#') t=NULL;

else

{t=(Bintree)malloc(sizeof(bintree));

t-data=ch;

t-lchild=initiate();

t-rchild=initiate();

}

return t;

}

void Visit(Bintree p)//访问节点

{printf("%c",p-data); //输出是char

}

int height(Bintree t)

{int ld,rd;

if(t==NULL) return 0;

else 

{ld=height(t-lchild);

rd=height(t-rchild);

return 1+(ldrd?ld:rd);

}

}

void levelorder(Bintree bt)//层次遍历

{LKQue Q;Bintree p;

InitQueue(Q);

if(bt!=NULL)

{EnQueue(Q,bt);

while(!EmptyQueue(Q))

{p=GetHead(Q);

OutQueue(Q);

Visit(p);

if(p-lchild!=NULL)  EnQueue(Q,p-lchild);

if(p-rchild!=NULL)  EnQueue(Q,p-rchild);

}

}

}

void main()

{Bintree T;

T=initiate();

printf("%d",height(T));

levelorder(T);

}

C语言 很简单的链表编译器不给过 找不出问题

return "head"; 为什么函数返回是字符串,你的返回类型是结构体指针的

cannot convert `const char*' to `a*' in return

不能反转char * 到 a* 的返回值

#include stdio.h

#include malloc.h

#define Len sizeof(a)

#define null 0

#include conio.h

struct a

{

int k;

struct a *next;

};

struct a* gethead()//建立

{

struct a *head, *p2;

printf("please enter data.");

head=p2=(struct a*)malloc(Len);

scanf("%d",p2-k); //输入要地址

while(p2-k!=0)

{

p2-next=(struct a*)malloc(Len);

p2=p2-next;

scanf("%d",p2-k); //输入要地址

}

p2-next=null;

return head; //返回指针

}

main()

{

struct a * head=gethead(); //变量名都没有

}

C语言数据结构打印杨辉三角

有两个地方错误

1:IsEmpty函数中是空返回真,非空返回假,你写反了

int IsEmpty(LinkQueue *Q)

{

if(Q-front==Q-rear)

return(TRUE);////////////

else  return(FALSE);/////////////

}

2:GetHead函数中*x=Q-front-next-data;因为Q-front只是头指针,不保存数据

int GetHead(LinkQueue *Q,int *x)

{

if(!IsEmpty(Q))

{

*x=Q-front-next-data;///////////////

return(TRUE);

}

else return(FALSE);

}

C语言 关于数据结构队列的问题 高分悬赏 各位高手请慢慢看

就几个明显的错误提一下

1. 函数 enterqueue中

s-queue[s-tear];

这句没有实际操作,估计应该是 s-queue[s-tear] = x; 用于在队列最后添加一个新的元素

2. 主函数中,大约21行左右

for(j=0;jk;j++)

{

deletequeue(l,e);

if(gethead(l,f)==0) // 这里多了一个分号,导致判断后没有任何动作可之心,删之

*f=0;

*e=*e+*f;

enterqueue(l,*e);

}

3. 主函数大约30行左右,打印输出

for(j=0;jl-tear;j++,p++) // 这里不可用i作循环变量,否则干扰外循环i

printf("%d ",*p);

4. deletequeue(l,e);

if(gethead(l,f)==0) // 多了分号

*f=0;

*e=*e+*f;

从语句目的看,是希望从deletequeue和gethead函数中,得到e或者f的地址,但是 1)由于传递的是指针的值,所以即使函数中修改了,主函数中无法得到新的地址;2)这两个函数体中,并没有设置地址的代码,总之,e 和 f 是没有可操作地址的

5. 最重要一点,没有看懂解题思路是什么。

即使按照删一个节点,再添两个节点的想法,也应该从队列的后面开始,这样间隔相加,并放在后移一个位置上,不至于影响后续计算。而这段程序从前开始修改队列,那新的节点产生,不就干扰后面的计算了?

所以,建议先说明一下解题思路,这样便于解决程序中的各种问题。


分享文章:c语言gethead函数 C语言head
URL分享:http://bjjierui.cn/article/hhsdoe.html

其他资讯