리스트 재 질문입니다.
크나
일단 제가 만들긴 해봤는데 먼가 에러가 뜨는 것 같아서요..
머가 잘못됬는지 좀 봐주세요..
#include stdio.h
#include stdlib.h
#define MAX_LIST_SIZE 100
typedef int element;
typedef struct {
int list[MAX_LIST_SIZE];
int length;
} ArrayListType;
void error(char *message)
{
fprintf(stderr,%s\n,message);
exit(1);
}
void init(ArrayListType *L)
{
L-length = 0;
}
int is_empty(ArrayListType *L)
{
return L-length == 0;
}
int is_full(ArrayListType *L)
{
return L-length == MAX_LIST_SIZE;
}
void display(ArrayListType *L)
{
int i;
for(i=0;iL-length; i++)
printf(%d\n, L-list[i]);
}
void add(ArrayListType *L, int position, element item)
{
if(!is_full(L) && (position =0) &&
(position = L-length))
{
int i;
for(i=(L-length-1); i=position; i--)
L-list[i+1]=L-list[i];
L-list[position]=item;
L-length++;
}
}
element delete(ArrayListType *L, int position)
{
int i;
element item;
if(position0 || position=L-length)
error(위치 오류);
item=L-list[position];
for(i=position; i(L-length-1); i++)
L-list[i]=L-list[i+1];
L-length--;
return item;
}
void replace(ArrayListType *L, int position, element item)
{
L-list[position]=item;
}
main()
{
ArrayListType list1;
init(&list1);
add(&list1, 0, 10);
add(&list1, 0, 20);
add(&list1, 0, 30);
add(&list1, 0, 40);
add(&list1, 0, 50);
display(&list1);
add(&list1, 4, 15);
display(&list1);
delete(&list1, 2);
display(&list1);
add(&list1, 0, 60);
display(&list1);
replace(&list1, 2, 30);
display(&list1);
free(&list1);
}