Sunday, July 28, 2013

Simple Insert Single Link List Program in C Language

#include<stdio.h>
#include<conio.h>

struct node
{
int data;
struct node *link;
};
struct node *header,*ptr,*newx,*temp;


void getnode()
{
int x;
newx=(struct node*)malloc(sizeof(struct node*));

scanf("%d",&x);
newx->data=x;

temp=header->link;
header->link=newx;
newx->link=temp;
}

void printnode()
{
ptr=header;

while(ptr->link!=NULL)
{
ptr=ptr->link;
printf(" %d ",ptr->data);
}
}

void main()
{
clrscr();

getnode();

printnode();

getch();
}

No comments:

Post a Comment