A
aki
Hi Frnds ,
Can u reply to my query ..
thanks
Aki
#include<iostream>
using namespace std;
const int NU=10;
struct node {
int data;
node *ptr;
};
int main()
{
int NU;
cout<<"enter nu"<<endl;
cin>>NU;
node* ARR[NU]; // Array of pointers to type node Is this Ok
for(int i=1;i<=NU;i++)
{
ARR=new node;
ARR->data=i;
}
for(int i=1;i<=NU-1;i++)
{
ARR->ptr =ARR[i+1];
}
node *head=ARR[1];
ARR[NU]->ptr=NULL;
node *tmp =head;
while(tmp->ptr!=NULL)
{
static int c=1;
cout<<"node"<<c<<"="<<tmp->data<<endl;
c++;
tmp=tmp->ptr;
}
return 0;
}
output
enter nu
7
node1=1
node2=2
node3=3
node4=4
node5=5
node6=6
Why is 7th node not getting printed???
Can u reply to my query ..
thanks
Aki
#include<iostream>
using namespace std;
const int NU=10;
struct node {
int data;
node *ptr;
};
int main()
{
int NU;
cout<<"enter nu"<<endl;
cin>>NU;
node* ARR[NU]; // Array of pointers to type node Is this Ok
for(int i=1;i<=NU;i++)
{
ARR=new node;
ARR->data=i;
}
for(int i=1;i<=NU-1;i++)
{
ARR->ptr =ARR[i+1];
}
node *head=ARR[1];
ARR[NU]->ptr=NULL;
node *tmp =head;
while(tmp->ptr!=NULL)
{
static int c=1;
cout<<"node"<<c<<"="<<tmp->data<<endl;
c++;
tmp=tmp->ptr;
}
return 0;
}
output
enter nu
7
node1=1
node2=2
node3=3
node4=4
node5=5
node6=6
Why is 7th node not getting printed???