Please help me to create an output like this
Enter a number: 1
Number you entered : 1
Enter a number: 2
Number you entered: 1 2 3
Enter a number: 3
Number you entered: 1 2 3
sample program please?
Please help me to create an output like this
Enter a number: 1
Number you entered : 1
Enter a number: 2
Number you entered: 1 2 3
Enter a number: 3
Number you entered: 1 2 3
sample program please?
Here, let me google that for you:
http://www.codeproject.com/Articles/24684/How-to-create-Linked-list-using-C-C
Thanks DeanMSands3, but I can't understand whats written on that page, I'm a starter on this language(c++)
Think of a list as a treasure hunt. You need to know where to start, where to go next, and as an added bonus every time you get to a given spot you can get a piece of treasure (data, information, whatever). Each spot along the way would be called a node. Each node will need to have some data and information about where to go next, which is typically an address (which in C++ is a pointer). Since the data and the pointer aren't likely to be the same type, then you will need a container of some sort to hold both types of data; that would be a user defined type, typcially called a struct (good for both C and C++) or a class (C++ only). Keeping track of the first place to go is the same as using a node with a given name, frequently called head. To create new nodes you will use dynamic memory using the keyword new. You assign input to the data variable(s) in the new node and since you don't know where to go from the new node to next node yet, make the next node zero, or in C++ language, NULL, if your prefer. Then you decide where to put the new node in the list (typically you add the new node in three places, always at the front, always at the back or randomly within the list). In your case you will always be adding to the back of the list. To find the back of the list you start at head and then to next node indicated in the current node. If the next node is NULL, then the current node is the last node and you can assign the new to be the next node in the list. Once you have gone everyplace you want to go you can start at head again and go from one node to the next, displaying the data in each node as you go.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.