Powered By Blogger

Monday, May 4, 2009

C Programming

#include
#include
#define NULL 0
struct node
{
int data;
char str[20];
node *next;
};
class linklist
{
node *list,*nptr,*tptr;
public:
linklist()
{
list=NULL;
}
void newnode(int item,char name);
void link();
void showdata();
};
void linklist::newnode(int item,char name[])
{
nptr=new (node);
nptr->data=item;
//nptr->next=NULL;
nptr->next->str=name;
nptr->next=NULL;
}
void linklist::link()
{
if(list==NULL)
{
list=nptr;
tptr=nptr;
}
else
{
tptr->next=nptr;
tptr=nptr;
}
}
void linklist ::showdata()
{
node *curptr;
curptr=list;
while(curptr!=NULL)
{
printf("%d",curptr->data);
printf("%s",curptr->str);
curptr=curptr->next;
}
}
int main()
{
clrscr();
int n,d;
char s[20];
linklist mylist;
printf("How many node you have:");
scanf("%d",&n);
printf("Enter data for node:");
for(int i=0;i
{
scanf("%d",&d);
scanf("%s",s);
mylist.newnode(d,s);
mylist.link();
}
printf("Data in the list:");
mylist.showdata();
getch();
return 0;
}

0 comments:

About This Blog

This is an important blog about updated news about computer science and technology.

Blog Archive

Visitors

  © Free Blogger Templates Blogger Theme II by Ourblogtemplates.com 2008

Back to TOP