#include<stdio.h>
#define MAX 100
char List[MAX] ;
/*
* Initializes the list.
* */
void InitializeList()
{
int i;
for( i=0;i<10;i++)
{
List[i] = 'A'+i;
}
}
/***************Gets the element count in array.******************/
int GetListLength()
{
int length = 0;
char *p = List;
while((*p)!='/0')
{
p++;
length++;
}
return length;
}
/*
* Shows all elements in the List.
* */
void ShowData()
{
char *p = List;
while((*p)!='/0')
{
printf("%c/t",*p);
p++;
}
printf("/n");
}
/*
* Adds a new element to the array.
*
* */
void AddElement(char data, int index)
{
int i;
int length = GetListLength();
//Checks whether the list is full now.
if(length == MAX - 1)
{
printf("The List is full now");
return;
}
if((index<0) || (index>length))
{
printf("The insert index is inlegal");
return;
}
for(i=length - 1;i>=index;i--)
{
List[i+1] = List[i];
}
List[index] = data;
}
/*
* Deletes element by the given index.
* */
void DeleteElement(int index)
{
int i;
int length = GetListLength();
//Checks whether the list is full now.
if(length == 0)
{
printf("The List is empty now");
return;
}
if((index<0) || (index>length - 1))
{
printf("The delete index is inlegal");
return;
}
for(i=index;i<length;i++)
{
List[i] = List[i+1];
}
List[i] = '/0';
}