#include <stdio.h>
#include <stdlib.h>
#define INIT_LENGTH 100;
struct ArrayList
{
int *dataSet;
int length;
int initLength;
};
void initList(struct ArrayList*);
void initListSize(struct ArrayList*, int);
void add(struct ArrayList*, int);
void addInIndex(struct ArrayList*, int, int);
void erase(struct ArrayList*,int);
void replace(struct ArrayList*, int, int);
void reset(struct ArrayList*);
void display(struct ArrayList*);
int get(struct ArrayList*, int);
int isFull(struct ArrayList*);
int isEmpty(struct ArrayList*);
int isAvailableIndex(struct ArrayList*, int);
void initList(struct ArrayList* list){
list->initLength = INIT_LENGTH;
list->dataSet = calloc(list->initLength,sizeof(int));
list->length = 0;
}
void initListSize(struct ArrayList* list, int size){
initList(list);
list->initLength = size;
}
void add(struct ArrayList* list, int value){
if(!isFull(list)){
list->dataSet[list->length] = value;
list->length++;
} else
printf("배열이 가득 찼습니다.");
}
void addInIndex(struct ArrayList* list, int index, int value)
{
;
}
void erase(struct ArrayList* list,int index){
if(isAvailableIndex(list, index)){
;
}
}
void replace(struct ArrayList* list, int index, int value){
if(isAvailableIndex(list, index))
list->dataSet[index] = value;
}
void reset(struct ArrayList* list)
{
int originSize = list->initLength;
free(list);
initListSize(list, originSize);
}
void display(struct ArrayList* list){
int i;
for(i = 0 ; i < list->length ; i++)
printf("[ %d ] ", list->dataSet[i]);
printf("\n");
}
int get(struct ArrayList* list, int index){
if(isAvailableIndex(list, index))
return list->dataSet[index];
}
int isFull(struct ArrayList* list){
return list->initLength == list->length;
}
int isEmpty(struct ArrayList* list){
return list->length == 0;
}
int isAvailableIndex(struct ArrayList* list, int index){
if(index > -1 && index < list->initLength && index < list->length)
return 1;
else
return 0;
}
void main(){
int i;
struct ArrayList* list = malloc(sizeof(struct ArrayList));
initList(list);
for(i = 1 ; i < 100 ; i += 5){
add(list, i);
}
display(list);
}