Friday, 7 November 2014

Link_List "1 to n" (DEV-C++)

#include<iostream>
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

Mini Library

  CLICK HERE  for Opening Mini Library Stuff Books are available in URDU & ENGLISH