链表问题 [英] linked list problem

查看:74
本文介绍了链表问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从我用C语言编程以来已经有一段时间了,我很困惑为什么我会得到以下错误信息(为什么他们都不是'指针)结构

chromT {}"?:


" genet.c",第192行:警告:作业类型不匹配:

指向struct的结果{double score,enum {worst(2),mid(1),best(0)}

cat,array [10]指向struct geneT {..}的指针基因,结构指针

chromT {..} next}" ="指向struct chromT的指针{}

我的代码如下(I已经注意到了问题的界限):


//数据结构


typedef struct {

双得分;

categ cat;

struct geneT *基因[GENES_PER_CHROM];

struct chromT * next;

} chromT;


typedef struct {

double x [PTS_PER_FEAT];

double id; //跟踪每个功能。

} geneT;

// F. UNCTION PROTOTYPES

static void * LLGo(chromT * start,int n);


/ * LLGo

*

*此函数返回第n个的地址。元素

*在链表中。

* /

static void * LLGo(chromT * start,int n){

int i = 0;

chromT * cursor = start;


while((cursor-> next!= NULL)&& ;(i< n)){

cursor = cursor-> next; //这就是问题的界限

i ++;

}

if(i< n){

返回NULL;

}

else {

返回光标;

}

}

解决方案

在文章< bo ********** @ news.Stanford.EDU>中,

Darius Fatakia< da ************ @ yahoo.com>写道:

自从我用C编程以来已经有一段时间了,我很困惑为什么我得到以下错误信息(为什么他们俩都没有指向struct的指针
chromT {}?:

" genet.c",第192行:警告:赋值类型不匹配:
指向struct {double score的指针,enum {最差(2),mid(1),最佳(0)}
cat,array [10]指向struct geneT {..}基因,指向struct的指针
chromT {.. } next}" ="指向struct chromT的指针{}

我的代码如下(我已注意到问题所在的行):

//数据结构

typedef struct {
分类cat;
struct geneT *基因[GENES_PER_CHROM];
struct chromT * next;
} chromT;

typedef struct {
double x [PTS_PER_FEAT];
double id; //跟踪每个功能的东西。
} geneT;




在第一个typedef中:


哟你指的是struct geneT,但是你还没有定义struct geneT。

你引用的是struct chromT,但是你还没有定义一个struct geneT。 struct chromT"。


试试这个:


typedef struct {

double x [PTS_PER_FEAT];

double id; //跟踪每个功能的东西。

} geneT;


typedef struct chromT {//注意:struct chromT

双重分数;

分类猫;

geneT *基因[GENES_PER_CHROM]; //注意:geneT,而不是struct geneT

struct chromT * next;

} chromT;

-

Rouben Rostamian< ro ******* @ umbc.edu>


谢谢!!!

It''s been a while since I programmed in C, and I''m confused as to why I get
the following error message (why aren''t they both "pointer to struct
chromT{}"?:

"genet.c", line 192: warning: assignment type mismatch:
pointer to struct {double score, enum {worst(2), mid(1), best(0)}
cat, array[10] of pointer to struct geneT {..} genes, pointer to struct
chromT {..} next} "=" pointer to struct chromT {}

my code is as follows (I have noted the line with the problem):

// DATA STRUCTURES

typedef struct {
double score;
categ cat;
struct geneT *genes[GENES_PER_CHROM];
struct chromT *next;
} chromT;

typedef struct {
double x[PTS_PER_FEAT];
double id; // something to keep track of each feature.
} geneT;
// FUNCTION PROTOTYPES
static void *LLGo (chromT *start, int n);

/* LLGo
*
* This function returns the address of the "n-th" element
* in the linked list.
*/
static void *LLGo (chromT *start, int n) {
int i = 0;
chromT *cursor = start;

while((cursor->next != NULL) && (i < n)) {
cursor = cursor->next; // THIS IS THE LINE WITH THE PROBLEM
i++;
}
if(i < n) {
return NULL;
}
else {
return cursor;
}
}

解决方案

In article <bo**********@news.Stanford.EDU>,
Darius Fatakia <da************@yahoo.com> wrote:

It''s been a while since I programmed in C, and I''m confused as to why I get
the following error message (why aren''t they both "pointer to struct
chromT{}"?:

"genet.c", line 192: warning: assignment type mismatch:
pointer to struct {double score, enum {worst(2), mid(1), best(0)}
cat, array[10] of pointer to struct geneT {..} genes, pointer to struct
chromT {..} next} "=" pointer to struct chromT {}

my code is as follows (I have noted the line with the problem):

// DATA STRUCTURES

typedef struct {
double score;
categ cat;
struct geneT *genes[GENES_PER_CHROM];
struct chromT *next;
} chromT;

typedef struct {
double x[PTS_PER_FEAT];
double id; // something to keep track of each feature.
} geneT;



In the first typedef:

you refer to "struct geneT", but you haven''t defined a "struct geneT".
you refer to "struct chromT", but you haven''t defined a "struct chromT".

Try this:

typedef struct {
double x[PTS_PER_FEAT];
double id; // something to keep track of each feature.
} geneT;

typedef struct chromT { // note: struct chromT
double score;
categ cat;
geneT *genes[GENES_PER_CHROM]; // note: "geneT", not "struct geneT"
struct chromT *next;
} chromT;
--
Rouben Rostamian <ro*******@umbc.edu>


Thanks!!!


这篇关于链表问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆