Wednesday, 8 August 2012

Linked list Using C programming

#include<stdio.h>
#include<conio.h>
#define a[30]
int*roll=NULL,top=-1;
void createlist();
void insertlist();
void deletelist();
void viewlist();
void displaymenu();
void creatememory();
void removememory();
void main()
{
int ch;
clrscr();
creatememory();
displaymenu();
while(1)
{
printf("\n");
scanf("%d",&ch);
switch(ch)
{
case 0:
displaymenu();
break;
case 1:
createlist();
break;
case 2:
insertlist();
break;
case 3:
deletelist();
break;
case 4:
viewlist();
break;
default:
removememory ();
printf("\n End of run of your program");
exit(0);
}
}
}
void displaymenu()
{
printf("\n Basic operation in linear list");
printf("\nmenu");
printf("\n\t1.create list");
printf("\n\t2.insert");
printf("\n\t3.delete");
printf("\n\t4.view list");
printf("\n\t5.exit");
printf("\n\t ENTER YOUR CHOICE");
}
void createlist()
{
char ch;
do
{
printf("\n ENTER THE VALUE TO BE INSERTED");
scanf("%d",&ch);
}
while((ch=='y')||(ch=='Y'));
}
void insertlist()
{
int i;
if(top==roll[30])
{
printf("\n The linear list is full");
return;
}
top++;
for(i=top;i>0;i--)
roll[i]=roll[i-1];
printf("\nEnter the element to added");
scanf("%d",&roll[0]);
}
void deletelist()
{
int i,deleteddata;
if(top==-1)
{
printf("\n Linear list is empty");
return;
}
top--;
deleteddata=roll[0];
for(i=0;i<=top;i++)
roll[i]=roll[i++];
printf("\n DELETED data is %d\n",deleteddata);
}
void viewlist()
{
int i;
if(top==-1)
{
printf("\nlinear list is empty");
return;
}
printf("\n element:");
for(i=0;i<=top;i++)
printf("\nenter the element....%d",roll[i]);
}
void creatememory()
{
roll=(int*)malloc(sizeof(int*));
}
void removememory()
{
free(roll);
roll=NULL;
}

No comments:

Post a Comment

There was an error in this gadget