#include<iostream.h>
#include<conio.h>
struct node
{
int info;
node *link;
};
void main()
{
clrscr();
cout<<"\n ------- Linked List Traversing -------\n\n";
node a[100];
node *start=&a[1];
int n,i,item;
cout<<"Enter No. of Nodes in Linked List : ";
cin>>n;
cout<<"\nEnter Info of Nodes :\n";
for(i=1;i<=n;i++)
{
cout<<"Node "<<i<<" : ";
cin>>a[i].info;
a[i].link=&a[i+1];
}
a[n].link=0;
cout<<"\nAfter Traversing : \n";
i=1;
while(start!=0)
{
cout<<"Node "<<i<<" : "<<a[i].info<<endl;
i++;
start=start->link;
}
getch();
}
Output :-
0 comments:
Post a Comment