#define max 50;
stuct list
{
char a[max];
int size;
}
typedef struct list LIST;
void traversal(LIST);
void insertfirst(LIST*,char);
void insertpos(LIST*,char,int);
void insertlast(LIST*,char);
void deletefirst(LIST*);
void deletepos(LIST*,int);
void deletelast(LIST*);
int find(LIST*,char);
int isempty(LIST*);
int iffull(LIST*);
void deletea(LIST*,char);
char findelm(LIST*,int);
//implementation file
#include"header.h"
//to check empty list
int isempty(LIST *L)
{
if(L->size==0)
return 0;
else
return 1;
}
//to check full list
int isfull(LIST *L)
{
if(L->size==max)
return 1;
else
return 0;
}
//travesre operation
void traversal(LIST L)
{
int i;
for(i=0;i
L->a[i+1]=L->a[i];
L->a[0]=x;
L->size++;
}
else
printf("cannot be inserted");
}
//insertat end
void insertend(LIST *L,char x)
{
int i,a;
a=isfull(L);
if(a==1)
{
i=L->size;
L->a[i]=x;
L->size++;
}
else
printf("cannot be inserted");
}
//to insert at given positon
void insertpos(LIST *L,char x,int ps)
{
int i,a;
a=isfull(L);
if(a==1)
{
for(i=L->size-1;i>=ps-1;i--)
L->a[i+1]=L->a[i];
L->a[ps-1]=x;
L->size++;
}
else
printf("cannot be inserted");
}
// delete at first
void deletefirst(LIST *L)
{
inti,a;
a=isempty(L);
if(a==1)
{
for(i=0;i
L->a[i]=a->a[i+1];
L->size--;
}
else
printf("deletion not possible");
}
//to delete last
void deletelast(LIST *L)
{
int i,a;
a=isempty(L);
if(a==1)
L->size--;
else
printf("deletion not posible");
}
// delete by positon
void deletepos(LIST *L,int pos)
{
int i,a;
a=isempty(L);
if(a==1)
{
for(i=pos;i
L->a[i-1]=L->a[i]
L->size--;
}
else
printf("deletion is not possible");
}
//delete the given elemt
void deletea(LIST *L,char x)
{
int i=0;int pos=0;
for(i=0;i
{
if(L->a[i]!=x)
pos++;
break;
}
deletepos(&L,pos); }
//to contruct
void read (LIST *L)
{
int n;
printf("ENTER NO OF ELEMENTS:")
scanf("%d,&n");
L->size=n;
for(i=0;i<=n;i++) scanf("%c",&L->a[i]);
}
//to find positon when char is given
int find(LIST *L,char x)
{
int i=0;int pos=0;
for(i=0;i
{
if(L->a[i]!=x)
pos++;
break;
}
return(pos);
}
//to find ele,wen pos given
char findele(LIST *L,int p)
{
int i,a;
char x;
a=isempty(L);
if(a==1)
return(L->a[p-1]);
else
return(NULL);
}
No comments:
Post a Comment