jsh6303
jsh6303

Reputation: 2040

Linked List syntax: is "next" already defined?

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

Answers (1)

jester
jester

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

Related Questions