So we have been learning about linked lists in my CS class and I understand the concept just fine. However, when looking at an example program my professor assign the code he provided was different than what we were shown in class.
Here’s the code from the example:
struct itemType
{
string store_name, item_name;
int item_number, quantity;
float price;
} ;
struct node
{
itemType item;
node *next; //
**node (itemType it, node* n=NULL)
{
item=it;
next=n;
}**
};
I don’t understand why he called node within the node struct and have it take two parameters (the part in the code contained within the ‘**’). It looks like a constructor or something. Every example on linked lists I’ve googled or read about does not have that little bit of code there!
But any help you guys can give me would be greatly appreciated!
That example is C++ code. A class in C++ is an extension of the struct concept, in fact about the only difference between a class and a struct is that in a struct all members are public by default whereas in a class they are private by default. This is due to the historical beginnings of C++ as “C With Classes” – just replace struct with class, add “public:” and it will look less foreign: