리스트 질문 드립니다
냥냥
#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;
ArrayListType *plist;
init(&list1);
add(&list1, 0, 10);
add(&list1, 0, 20);
add(&list1, 0, 30);
add(&list1, 0, 40);
add(&list1, 0, 50);
display(&list1);
plist = (ArrayListType *)malloc(sizeof(ArrayListType));
init(plist);
add(plist, 0, 10);
add(plist, 0, 20);
add(plist, 1, 15);
add(plist, 0, 30);
add(plist, 0, 40);
add(plist, 0, 50);
display(plist);
free(plist);
}
위에서 delete 함수를 써서 30을 삭제 시키고
add 함수를 써서 60을 추가 시키고
replace 함수를 써서 40을 30으로 교환시키는 프로그램을 만드려고 하는데
막히네요...
도와주세요~~
-
빵야
추가 시켰습니다ㅋ
-
푸른마을
replace 함수가 어디있나요?
값 교환은 보통 swap함수로 해결이 가능합니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700610 | 정말 기초적인 더하기,여백 문제 help | 무슬 | 2025-07-06 |
2700562 | 함수포인터에서요 (7) | 소심한여자 | 2025-07-06 |
2700530 | 전처리문 질문입니다. (1) | 아놀드 | 2025-07-05 |
2700510 | c언어를 어케하면 잘할수 있을까요.. | 연연두 | 2025-07-05 |
2700484 | 두 개가 차이가 뭔지 알려주세요...(소수 찾는 프로그램) (2) | 날위해 | 2025-07-05 |
2700426 | 인터넷 창 띄우는 질문이요 (1) | 정훈 | 2025-07-04 |
2700400 | 원넓이를 계산이요 ㅜㅜ | 천칭자리 | 2025-07-04 |
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |
2700070 | while문 , 3의배수 출력하는 프로그램좀 짜주세욤. | 횃불 | 2025-07-01 |
2700041 | 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? | 헛장사 | 2025-07-01 |
2700012 | 배열// (1) | 전갈자리 | 2025-07-01 |