See I probably have the littlest knowledge on working with Linked Lists and I was thinking of creating a program that will accept three numbers which will be arranged on the list. However, I need to display the numbers everytime I input them, which I don't know how. My goal is to have this:
Give a number: 2
Display List: 2
Give a number: 3
Display List: 2 3
Give a number: 1
Display List: 1 2 3
I'm not actually familiar with how linked lists work so far so any explanation that would give light to this concept is highly appreciated. Thanks :)
#include<iostream>
#include<stdlib.h>
using namespace std;
int main(){
struct Node {
int data; // data in node
Node *next; // Pointer to next node
};
Node *p;
for(int i=0; i<3; i++)
{
p = new Node; //create a new node
cout << "Give a number: " ;
cin >> p->data;
cout << "\nDisplay List"<<p ->data<<" " ;
p -> next = NULL;
}
system("pause>null");
return 0;
}