473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem In linked list

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
2 1228
Ganon11
3,652 Expert 2GB
item is used in the same was as next. Both are pointers to a node.
Oct 10 '07 #2
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

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

Similar topics

5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
6
by: Steve Lambert | last post by:
Hi, I've knocked up a number of small routines to create and manipulate a linked list of any structure. If anyone could take a look at this code and give me their opinion and details of any...
10
by: Ben | last post by:
Hi, I am a newbie with C and am trying to get a simple linked list working for my program. The structure of each linked list stores the char *data and *next referencing to the next link. The...
57
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
11
by: bofh1234 | last post by:
Hello, I am having a problem with linked lists. My program is based on a client server model. The client sends some packets of data to the server. The server reads those packets and is...
0
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
12
by: kalyan | last post by:
Hi, I am using Linux + SysV Shared memory (sorry, but my question is all about offset + pointers and not about linux/IPC) and hence use offset's instead on pointers to store the linked list in...
6
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.