By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,016 Members | 2,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,016 IT Pros & Developers. It's quick & easy.

Problem In linked list

P: 1
When we make a node in a linked list using struct keyword, We usually declare a pointer named next/link as a member of a structure.

Also we make another pointer with name item( name for new node to be created) as a structure variable.

Syntax for declaring both is same. But usage is different.

For eg: next is called the address part of the node which contains the address of the next node in the list.

item is a node which contains both the parts--data part & address part.

struct node
{
int no;
node *next;
} *item;

void newele( )
{
item=new node;
cin>>item->no;
item->next=NULL;
}

In tha above example item is used as a node. While next is not considered as node. Why?

What is the difference b/w next & item?
Oct 10 '07 #1
Share this Question
Share on Google+
2 Replies


Ganon11
Expert 2.5K+
P: 3,652
item is used in the same was as next. Both are pointers to a node.
Oct 10 '07 #2

P: 3
When we make a node in a linked list using struct keyword, We usually declare a pointer named next/link as a member of a structure.

Also we make another pointer with name item( name for new node to be created) as a structure variable.

Syntax for declaring both is same. But usage is different.

For eg: next is called the address part of the node which contains the address of the next node in the list.

item is a node which contains both the parts--data part & address part.

struct node
{
int no;
node *next;
} *item;

void newele( )
{
item=new node;
cin>>item->no;
item->next=NULL;
}

In tha above example item is used as a node. While next is not considered as node. Why?

What is the difference b/w next & item?



hi good question first see how much memory is there for ITEM and NEXT.
here next size is 4(in linx) and the item size if size of item . because here they created the memory dynamically..
so youcannot save the entire structure in the 4bytes(NEXT).. so it will act as the pointer only..
ok clear or not
Oct 10 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.