Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...