My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

program to show basics of linklist

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct node
{ int info;
  node *link;
};
class linklist
{ node *start;
  public:
  linklist()
  { start=NULL; }
  void insertbeg(int);
  void show();
  void delfirst();
  void insertend(int);
  void dellast();
};
void linklist::insertbeg(int a)
{ node *p=new node;
  p->info=a;
  p->link=start;
  start=p;
}

 void linklist::show()
 { node *p=start;
   while(p!=NULL)
   { cout<<p->info<<endl;
     p=p->link;
   }
 }

 void linklist::delfirst()
 {   if(start==NULL)
     { cout<<"there is no node in the linklist";
     }
     else
     {  node *p=start;
    start=p->link;
    p->link=NULL;
    delete p;
     }
 }
 void linklist::insertend(int b)
 { node *p=new node;
   p->info=b;
   p->link=NULL;
   if(start==NULL)
   start=p;
   else
   {
     node *q=start;
     while(q->link!=NULL)
     { q=q->link;
     }
     q->link=p;
   }
 }

0 comments: