Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difficulty understanding linked list implementation (the struct part)?

struct node
{ 
    int data;
    struct node *next;
}*start;

I don't understand what struct node *next does, I know it points to the address of the next variable; but how as in implementation? Is node *next similar to struct node *next?

And what about the *start is it similar to struct node *start?

I am finding very difficulty understanding linked lists implementation.

like image 904
AdiL IsmaiL Avatar asked Nov 27 '25 03:11

AdiL IsmaiL


1 Answers

I don't understand what struct node *next does, I know it points to the address of the next variable; ...

This is correct.

... but how as in implementation ?

The implementation is pretty much exactly how you described the behaviour: A pointer is implemented as an object whose value is the memory address of the pointed object.

Is node *next similar to struct node *next?

Not only similar, but pretty much identical.


And what about the *start is it similar to struct node *start?

It is struct node *start. See the complete declaration:

struct node /* structure definition */ *start;

It is a combined declaration of a variable, and definition of a structure.


† The struct keyword is just used to disambiguate that the following identifier is in the name space†† of structure tags. In your case it is redundant, because there are no non-structure identifier Node to disambiguate, and in C++ structure tags are also type names.

What you're probably looking at is C code, where the name space†† specifier is mandatory for structure tags.

†† In this context, I refer to C name spaces, not C++ name spaces.

like image 120
eerorika Avatar answered Nov 28 '25 16:11

eerorika



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!