Friday, April 17, 2009

INSERTION OF DATA USING LINKED LIST

/*insertion of data using linked list*/
#include
#include
#include
struct node
{
int data;
struct node *next;
};
typedef struct node node;
node *FRONT=NULL;
node *REAR=NULL;
void insert()
{
node *t;
int data;
printf("enter the data");
scanf("%d",&data);
t=(node *)malloc(sizeof(node));
t->data=data;
t->next=NULL;
if(REAR==NULL)
{
REAR=FRONT=t;
}
else
{
REAR->next=t;
REAR=t;
}
}
int delete()
{
int temp;
node *t;
if(FRONT==NULL)
{
puts("\n\nQ underflows");
return -999999;
}
else
{
t=FRONT;
FRONT=FRONT->next;
temp=t->data;
if(FRONT==NULL)
{
REAR=NULL;
}
free(t);
return temp;
}
}
void main()
{
int i;
clrscr();
for(i=0;i<5;i++)
insert();
for(i=0;i<5;i++)
printf("\n%d-deleted",delete());
getch();
}

No comments: