Jul 29, 2016 at 8:35am UTC
Am trying to learn linked lists in c++ but I have failed to display what I enter in the linked list
can anyone help me find what am missing out please.
here is the code below
#include<iostream>
using namespace std;
struct node
{
int num;
node*n_ext;
};
node*nodes=NULL;
int main()
{
for(int i=10;i!=0;)
{
node*p_node=new node;
cin>>i;
p_node->num=i;
p_node->n_ext=nodes;
nodes=p_node;
}
node*p_current_node=nodes;
if(p_current_node!=NULL)
{
cout<<p_current_node->num<<"\n";
p_current_node=p_current_node->n_ext;
}
}
Last edited on Jul 29, 2016 at 8:38am UTC
Jul 29, 2016 at 11:07am UTC
I thnk I have seen the problem i used if statement that is not used in looping
Jul 29, 2016 at 1:28pm UTC
Oh, it helped you.
Glad it helped :)