Traversing a single linked list with c

#include<stdio.h>
//Basic decleration of linked list with the help of referential structure A refential structure which use structure as a references.
//linked list declerations
struct node
{
int value;
struct node *link;

};
//Main method operation performed
void main()
{
struct node *p,n1,n2,n3,n4,n5;//for traversing purpose we create a structure pointer p.and also five nodes.
struct node *start=&n1;//In linkedin we only access or operation perform by the help pointer start.

n1.value=100;
n1.link=&n2;
n2.value=200;
n2.link=&n3;
n3.value=300;
n3.link=&n4;
n4.value=400;
n4.link=&n5;
n5.value=500;
n5.link=NULL;

if(start==NULL)
{
printf(“Linked List is Empty\n”);
return;
}
p=start;
printf(“The list is\n”);
while(p!=NULL)
{
printf(“%d”, p->value);
p=p->link;
}
printf(“\n\n”);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s