Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

java - Problems understanding concept of nodes and linked list

i am new to Data Structures and Algorithim and i am having some troubles getting around the whole topic of linked list and how its connected to nodes. The problem that is confusing me is with pointers and what they point to

This is a sample question off a textbook

(i) "What happens to the pointer head when the object obj is added to an empty linked list?"
 head1 = new listNode(obj, head);
(ii) Write A Constructor to represent (i)

I've seen that stack overflow is the place to get some help, and i need some immediate help, all thoughts will be deeply appreciated. Thanks in Advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem that is confusing me is with pointers and what they point to?

In java reference works as pointer to an object in memory that internally can point to another one in the same way.

Let's try to understand it visually:

What happens to the pointer head when the object obj is added to an empty linked list?

In below snapshot head is a reference that point to first object in the memory and first object contains another reference next that points to second object and so on...

enter image description here

Write A Constructor to represent (i)

I think that you can do it as your homework.

Hint: (As shown in above snapshot as well)

  1. create a new node
  2. point next of new node to next of head
  3. point head to new node

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...