链接列表问题 [英] Link list problem

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

问题描述



这是在接受采访时向我询问的问题。

我无法找到答案

。请试着看看关于

以下问题可以做些什么。


/ *我有两个结构* /

struct node

{

struct node * next;

} * temp;


struct数据

{

int a;

浮动b;

char c;

struct node s;

};


/ *现在的问题是使用temp * /


提前致谢。

Hi,
This is a question asked to me in an interview.
I haven''t been able to figure out an answer for
it. Please try to see what can be done about the
following problem.

/* I have been given two structures */
struct node
{
struct node *next;
} *temp;

struct data
{
int a;
float b;
char c;
struct node s;
};

/* Now the question is to access the values of a,b,c using temp */

Thanks in advance.

推荐答案

文章< 11 ******* ***************@g43g2000cwa.googlegroups .com> ;,

Shwetabh< sh ********** @ gmail.com>写道:
In article <11**********************@g43g2000cwa.googlegroups .com>,
Shwetabh <sh**********@gmail.com> wrote:
这是一个在接受采访时向我询问的问题。
我还没有找到答案。
它。
/ *我已经给了两个结构* /
struct node
{struct node * next;
} * temp;
struct data
{
int a;
float b;
char c;
struct node s;
};
/ *现在的问题是使用temp * /
This is a question asked to me in an interview.
I haven''t been able to figure out an answer for
it. /* I have been given two structures */
struct node
{
struct node *next;
} *temp; struct data
{
int a;
float b;
char c;
struct node s;
}; /* Now the question is to access the values of a,b,c using temp */

访问a,b,c的值

结构节点的定义可能略有不同,作为


struct node

{

struct data * next;

} * temp;

如果没有,那么没有某种作弊就无法完成,因为

显然临时访问的任何东西都是指针。

当然有准备作弊,例如在
中创建上下文,temp是指向结构数据而不是结构节点的指针。

-

哦,要成为Blobel!



Is it possible that struct node is defined slightly differently, as

struct node
{
struct data *next;
} *temp;
If not then it can''t be done without some kind of cheating, as
clearly anything accesses by temp will be a pointer.

There is, of course, ready cheating, such as creating a context in
which temp is a pointer to a struct data instead of a struct node.
--
Oh, to be a Blobel!


Shwetabh写道:
Shwetabh wrote:

这是在接受采访时向我提出的一个问题。
我无法找到答案。
它。请试着看看关于
以下问题可以做些什么。

/ *我有两个结构* /
struct node
{
struct node * next;
} * temp;

struct data
{
int a;
float b;
char c;
struct node s;
};

/ *现在的问题是使用temp * /
Hi,
This is a question asked to me in an interview.
I haven''t been able to figure out an answer for
it. Please try to see what can be done about the
following problem.

/* I have been given two structures */
struct node
{
struct node *next;
} *temp;

struct data
{
int a;
float b;
char c;
struct node s;
};

/* Now the question is to access the values of a,b,c using temp */


<访问a,b,c的值br />
所以你说的是临时是一个指向会员数据的指针s?


没有便携式解决方案,因为无法确定

使用的填充量对于结构成员。您可以通过

来做猜测:


void * v = temp;

v - = sizeof(char)+ sizeof (float)+ sizeof(int);

struct data * d = v;


但这只有在结构没有填充的情况下才有效,这是一个无效的假设。


也许另一种可能性是:


struct data d;

void * dp =& d;

void * s =& ds;

int diff = s - dp;


void * v = tmp;

v - = diff;

struct data * answer = v;


即便如此,你可能还有一些特定于平台的问题。


Jon

----

学习使用Linux汇编语言的程序
http://www.cafeshops.com/bartlettpublish .8640017


Jonathan Bartlett< jo ***** @ eskimo.com>写道:
Jonathan Bartlett <jo*****@eskimo.com> wrote:
Shwetabh写道:
Shwetabh wrote:
struct node
{struct struct * next;
} * temp; <结构数据
{
int a;
浮动b;
char c;
struct node s;
};

/ *现在的问题是使用temp * /
访问a,b,c的值所以你要说的是temp。是指向成员s的数据的指针?
struct node
{
struct node *next;
} *temp;

struct data
{
int a;
float b;
char c;
struct node s;
};

/* Now the question is to access the values of a,b,c using temp */
So you are saying that "temp" is a pointer into data at member "s"?




不,他不是这么说的。他可能_meant_,因为没有一些

暗示这个谜题是无法解决的,但他没有说出来。

没有便携式解决方案,因为那里无法确定用于结构构件的填充量。



No, he isn''t saying that. He probably _meant_ that, since without some
hint of that ilk the puzzle is unsolvable, but he didn''t say it.
There is no portable solution, as there is no way to determine the
amount of padding used for structure members.




是的,对于已知的声明结构:offsetof。


(不,我不再提供任何提示。)


Richard



Yes, there is, for a known, declared structure: offsetof.

(No, I''m not giving any more hints.)

Richard


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

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