using namespace std;
struct node{
int data;
node *next;
};
int main()
{
int n;
cout<<"Enter the Number of LINK_LIST = ";
cin>>n;
node *ptr,*head,*lastn;
ptr=new node;
ptr->data=1;
ptr->next=NULL;
head=ptr;
lastn=ptr;
for(int i=2;i<=n;i++)
{
ptr=new node;
ptr->data=i;
ptr->next=NULL;
lastn->next=ptr;
lastn=ptr;
}
ptr=head;
while (ptr!=NULL)
{
cout<<"link-list = "<<ptr->data<<endl;
ptr=ptr->next;
}
return 0;
}
No comments:
Post a Comment