Linked Lists Questions
This is the basic declaration we do while working on linked lists.
struct node {
int data;
struct node* next;
};
why is the next declared as a pointer? and not as a just
struct node next; ??
I will start with basic and then go for advanced questions.
struct node {
int data;
struct node* next;
};
why is the next declared as a pointer? and not as a just
struct node next; ??
I will start with basic and then go for advanced questions.
Replies
-
aarthivg
linked list consist of two parts data and reference to the next nodeEnglish-ScaredThis is the basic declaration we do while working on linked lists.
struct node {
int data;
struct node* next;
};
why is the next declared as a pointer? and not as a just
struct node next; ??
I will start with basic and then go for advanced questions. -
Saandeep SreerambatlaTrue, but the reference can also be accessed by normal variables using logic!
and think in this perspective, is it valid if I declare
struct node {
int data;
struct node next;
};
If valid why dont we use, If invalid why is it invalid? -
aarthivgThe field of each node that contains the address of the next node is usually called the next link or next pointer.
So reference cant be used as a normal variable. -
Saandeep SreerambatlaOK the answer I was expecting is,
if we donot use a pointer, and declare a variable of struct node inside struct node, then compiler donot know how much memory to allocate to that variable as the parent structure declaration is not complete yet.
if we use a pointer, then compiler knows that , its a pointer and it stores address of something . so it allocates memory. -
greatcoderHere Because next is not a structure itself , it is a pointer to the next node in the linked list.
-
Saandeep Sreerambatla#-Link-Snipped-# Coder : Please elaborate!!
You are reading an archived discussion.
Related Posts
hello guys,
there is a robotics competition being held at RRS college of engineering & tech in muthangi, patancheru, hyderabad.
the events that will take place are
1. robo wars...
The Dolphin browser has finally arrived in the Blackberry App world. It's free to download and promises to be the free, fun and fast browser for your BBs. It's also...
New layout is just like gmail and discussion thread is also very simple yet beatiful.
I don't know if anyone here using google groups. but now its pretty good.
Earlier...
please share the mathematical model/derivation for the working of table tennis shooter machine.
i think it is based on principle conservation of momentum.
rotating wheel transfers momentum to the ball.
There comes a time in some peoples' lives when one feels burnt out and not able to take it any more. Quite often one is unaware of what is happening...