开发者

How to find address on an element of linked list? [closed]

开发者_开发知识库 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

If the address of the 8th element in a linked list of integers is 1022, then what is the address of 9th element and 15th element??

Explain in detail with example!!

I am really lazy, please do my homework for me.

thanx


There is no relation between the addresses of the elements of a linked list, each element may be located anywhere in memory. To find your answer, you must traverse the list until you get to the 9th or 15th element and take the address.

Or, in most languages and implementations of a linked list, you could traverse to the 8th or 14th element and note that the value of the "next element" pointer is the address of the next element.


For example, you have link list struct:

typedef struct tag_link {
   int data;
   tag_link* next;
} linked;

linked* eleventh; // points to 8th element
int* data_of_nineth = &(eleventh->next->data); // address of data of 9th element of list
linked* nineth = eleventh->next;               // address of 9th element of list

To get address of data in 15th element is best way to walt through next pointers until you find 15th element of linked list and then get address of what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜