Lab_4
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct nodenext;
}; struct node head,tail=NULL;
void addnode(int data)
{
struct nodenewnode=(struct node*)malloc(sizeof(struct node));
newnode->data=data;
newnode->next=NULL; if(head==NULL)
{
head=newnode;
tail=newnode;
}
else
{
tail->next=newnode;
tail=newnode;
}
}
int coundnode( struct node * head)
{
int length=0;
while(head!=NULL)
{
head=head->next;
length++;
}
return length;
}
void display()
{
struct node*current=head;
if(head==NULL)
{
printf("List is empty");
return;
}
while(current!=NULL)
{
printf("%d",current->data);
printf("->");
current=current->next;
}
printf("NULL");
}
int main()
{
clrscr();
addnode(1);
addnode(2);
addnode(3);
addnode(4);
display();
printf("\n \n length of linked list:%d",coundnode(head));
getch();
return 0;
}