Click here to Skip to main content
15,881,671 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i am running through some code on web but i am little confused about the code that because i dont understand (Difficult To understand )it and i want its alternate in simple form if any also if any explanation about that part it will be bonus !!

What I have tried:

C++
typedef struct node {
	int info;
	struct node *link;
}NODE;

also,
NODE* create(NODE *start)//function to create Node

VS
void disp(NODE *start)//function of display
Posted
Updated 21-Dec-16 10:39am
Comments
gggustafson 21-Dec-16 10:17am    
First, I'm using C as the reference language because it seems that's what you are providing.

The first piece of code defines a NODE, as in a list. Note that node includes a reference to itself (as a pointer). That means that the list can be traversed by moving from link to link. (I personally would have named "link" as "next"; it makes more sense.)

The create function returns a new NODE. Whatever is returned should be ready to have "info" filled; "link" made to point to some other NODE (like "start"); and some existing NODE in the list made to point to this new NODE.

The disp function would (I'm guessing) traverse the list beginning at "start". This implies that "link" should be set to nul in the last NODE of the list.

Hope that helps.
mayashah 21-Dec-16 12:07pm    
Absolutely :) Perfect !!

To be honest, if you don;t understand that, you need to go back and re-read the appropriate bits of your course - because this is pretty simple stuff that you should have covered and understood very well.

The first bit of code creates a structure - a user defined datatype if you like - which contains and integer and a pointer to another instance of the structure.
The second bit declares a function returning a pointer to the new instance of the structure that accepts a "start of list" pointer so it can (presumably) add the item into the existing list.

The last bit declares a function that returns no value, but accepts a pointer to the first element in the list that (probably) prints the whole list somewhere.

As I said: pretty basic stuff that you are almost certainly supposed to understand by now. If you don't, then re-read your course notes very carefully as this stuff is important!
 
Share this answer
 
Comments
mayashah 21-Dec-16 10:12am    
i don't understand it clearly i have read my notes clearly !!!
[no name] 21-Dec-16 10:17am    
Then ask your teacher. It's his job to teach you not ours.
OriginalGriff 21-Dec-16 10:32am    
Which bit do you not understand?
Those are simple form!
You need to learn properly C/C++.
Here is links to references books on C and C++ by the authors of the languages. Note than C is the ancestor of C++, so knowing C is always useful with C++.
The C Programming Language - Wikipedia, the free encyclopedia[^]
https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2.pdf[^]
http://www.ime.usp.br/~pf/Kernighan-Ritchie/C-Programming-Ebook.pdf[^]

C++ Programing Language[^]
 
Share this answer
 
Well, you don't specify what part you don't understand but that looks like a simple implementation of a "singly linked list[^]".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900