Reputation: 2040
I am new in Data Structure. I came up with a question when I was trying to write code using linked list using C++.
In linked list, is pointer next
, previous
defined by the compiler? Or we have to name our own and it does not matter how we call it?
Upvotes: 0
Views: 241
Reputation: 3489
next
and previous
are not predefined. We have to define it ourself. Usually for a single linked list, we come up with a node structure which consists of a data field and anext
pointer which is a pointer to a node of the same type. A simple example is as follows:
struct node{
int data; //data part
struct node *next; // next pointer - points to a node of the same type
}
Upvotes: 2