# include <stdio.h>
# include <malloc.h>
void inint(struct Arrylist *,int);//
bool add(struct Arrylist *, int, int);//
bool del(struct Arrylist *, int, int);
bool reverse(struct Arrylist *);
bool show(struct Arrylist *);//
bool is_empty(struct Arrylist *);//
bool is_full(struct Arrylist *);//
bool append(struct Arrylist *, int);
struct Arrylist
{
int * p;//the address of the first element of the arrylist
int con;//the real element number of the arrylist
int len;//the max of the length of the arrylist
};
int main(void)
{
struct Arrylist * ay;
inint(ay, 6);
append(ay, 1);
append(ay, 2);
append(ay, 3);
show(ay);
return 0;
}
bool is_full(struct Arrylist * arry)//judge a arry is full or not
{
if(arry->con == arry->len)
{
return true;
}
else
{
return false;
}
}
bool show(struct Arrylist * arry)// to show the arry
{
if( is_empty(arry) )
{
printf("The arrylist is empty!\n");
return false;
}
for(int i = 0; i < arry->con-1; i++)
{
printf("show the arry :%d", (arry->p)[i]);
}
return true;
}
void inint(struct Arrylist * arry, int len)//inintilization the arry
{
arry->p = (int *)malloc(sizeof(int)*len);
arry->con = 0;
arry->len=len;
return;
}
bool append(struct Arrylist * arry, int val)
{
if( is_full(arry) )
{
printf("the arry is full!\n");
return false;
}
arry->p[arry->con-1] = val;
arry->con++;
return true;
}
bool is_empty(struct Arrylist * arry)//judege whether a arry is empty or not
{
if(arry->con == 0)
{
return true;
}
else
{
return false;
}
}
bool add(struct Arrylist * arry, int pos, int val)//add element
{
if(is_full(arry))
{
printf("Arrylist is full!");
return false;
}
else if(pos < 1 || pos > arry->con+1)
{
printf("Wrong add!");
return false;
}
else
{
for(int i = arry->con; i > pos; i--)
{
(arry->p)[i-1] = (arry->p)[i-2];
}
(arry->p)[pos-1] = val;
arry->con++;
return true;
}
}