질문있어요 ㅜㅜ
꼬붕
#include stdio.h
#include stdlib.h#define MAX_LIST_SIZE 100typedef int el;typedef struct
{
int list[MAX_LIST_SIZE];
int length;
} ArrayListType;int init(ArrayListType *L) // list를 초기화
{
return L-length=0;
}int is_empty(ArrayListType *L) // 만약 길이가 0이라면 데이터가없는 거니까 값을 반환
{
return L-length==0;
}int is_full(ArrayListType *L) // 길지가 지정한 100까지 꽉 찾을 경우 반환
{
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, el item)
{ if(!is_full(L)&&(position=0)&&(position=L-length))// 값이 다 입력 됐을 때와 현재 삽입하려는 위치가 0보다 크고
{ // 삽입 하는 위치가 0보다 작으면 L-list[마이너스 값] 이면 오류출력 되므로 확인하고
int i; //그리고 삽입 위치가 현재 길이(데이터 들어있는 만큼 수)-1 보다 크지 않도록 하는 는 조건 문.
for(i=(L-length-1);i=position;i--) // 현재 길이 -1 시키면서 위치까지 감소시키면서 이전 값을 대입
L-list[i+1]=L-list[i]; // 위치 1에 값이 2번 값 자리에 들어감
L-list[position]=item;
L-length++;
}
}void replace(ArrayListType *L, int position, el item) // 현재 위치의 배열에 입력한 item을 대입
{
L-list[position]=item;
}void add_first(ArrayListType *L, el item)
{
add(L,0,item);
}void main()
{
ArrayListType list;
init(&list);
add_first(&list,10);
add_first(&list,20);
add_first(&list,30); display(&list);
}
위에 것을 밑에 처럼 해볼려고 하는데 좀 힘들어요 ㅜㅜ
함수를 만들으라는데 안되겟어요 ㅜㅜtypedef enum {insert, Delete, display, stop} opcode;
int main()
{
Araylisttype list;
opcode op; init(&list);
do
{
op=getop();
if (opstop) then
doexec(op,&list);
}while (opstop); return 0;
}void doexec(opcode op,arraylisttype *list)
{
switch(op)
{
case insert:doinsert(list);break;
case Delete:doDelete(list);break;
case display:display(*list);break;
default:error(); break;
};
}void doinsert(arraylisttype *list)
{}void doDelete(arraylisttype *list)
{}도와주시면 안될까요?? ㅜㅜ함수만들기도 어렵고ㅜㅜ 어떻게해야할까요??