배열을 이용한 선형리스트 함수 추가구현하기
소년틳터프
질문 제목 : 배열을 이용한 선형리스트 함수 추가구현하기질문 내용 : void replace(arraylist *l, int pos, int item)
void addfirst(arraylist *l, int item);
int deletelast(arraylist *l)
위 함수를 이용해서 함수 추가좀 해주세요 ㅠㅠ
#includestdio.h
#define max_length 100
typedef int element;
typedef struct{
int list[max_length+1];
int length;
} arraylist;
void initlist(arraylist *l)
{
l-length=0;
}
int getlength(arraylist *l)
{
return l-length;
}
int isfull(arraylist *l)
{
return(l-length == max_length);
}
void display(arraylist *l)
{
int i;
printf(\n 배열 출력 \n);
for(i=0;il-length;i++)
printf(%3d, l-list[i]);
printf(\n);
}
void add(arraylist *l, int item,int position)
{
int i;
if(isfull(l)==0&&(position =0) && (position = l-length)){
for(i=(l-length-1);i=position;i--)
l-list[i+1] = l-list[i];
l-list[position] =item;
l-length++;
}
}
element deleteitem(arraylist *l,int position)
{
int i;
int item;
if(position0 || position= l-length){
printf(위치오류);
return -1;
}
item = l-list[position];
for(i=position ; i (l-length-1);i++)
l-list[i] =l-list[i+1];
l-length--;
return item;
}
void addlast(arraylist *l,int item)
{
add(l,item,getlength(l));
}
int main()
{
arraylist list1;
initlist(&list1);
addlast(&list1, 10); addlast(&list1, 20); addlast(&list1, 40);
addlast(&list1, 50); addlast(&list1, 60); addlast(&list1, 70);
display(&list1);
add(&list1, 30, 2);
display(&list1);
deleteitem(&list1,2);
display(&list1);
getchar();
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2701754 | strcmp,strcpy를 좀더 이해를 하기위해서 간단히 만들었는데... | 말달리자 | 2025-07-17 |
2701724 | 배열초기화도중 이니셜라이저 가 너무 많다고 나오네요! (2) | 라임나무 | 2025-07-16 |
2701697 | 6.0에서는 잘되던 프로그램이 2008에서는 잘안된답니다. 한번 아시는분 댓글부탁드립니다. (1) | 빵순 | 2025-07-16 |
2701644 | 문자가 알파벳인지 검사하기(isalpha) | 마음 | 2025-07-16 |
2701590 | 재가 C프로그래밍 아무것도 몰르는데요. (4) | 대나무 | 2025-07-15 |
2701565 | 로그인 프로그램 | 개굴츼 | 2025-07-15 |
2701511 | 이거 오류 안나게 수정좀 부탁드릴께요 ㅠㅠ 돠주세요 ㅠㅠ | 어리버리 | 2025-07-14 |
2701453 | MFC문제점 해결방안좀알려주세요~~ | 나샘 | 2025-07-14 |
2701429 | 자료형에 관한 질문 (5) | 펴라 | 2025-07-14 |
2701377 | 훌로트형 변수를, 서식문자 %d로 읽기 vs 인트형 포인터로 참조하기 | LetMeGo | 2025-07-13 |
2701291 | 콘솔에서 종료시킬때 메시지를 안띄우려면 어떻게 해야하나요? (1) | 세실 | 2025-07-12 |
2701262 | 씨언어 좀 봐주세요 | 아담 | 2025-07-12 |
2701211 | 토큰추출 | 겨루 | 2025-07-12 |
2701159 | 연산자문제 알려주세요 | 도1도캣 | 2025-07-11 |
2701130 | 중적분문제입니다. 적분구간에 변수가 들어갈순 없나요??ㅡㅜ | 풀큰 | 2025-07-11 |
2701098 | 난수에 질문드립니다. | 큰뫼 | 2025-07-11 |
2701070 | 또다른 시험문제 질문올립니다 | 채련 | 2025-07-10 |
2701042 | 뭐가 잘못된건지 잘 모르겠습니다.;; | 지은 | 2025-07-10 |
2700986 | 뭐가 잘못된건지좀 봐주세요. | 우주 | 2025-07-10 |
2700932 | 도와주세요 ㅠㅠ 모르겟어요 ㅠ | 유희 | 2025-07-09 |