어느부분이틀렸는지 봐주세요ㅠㅠ 헬프
딸기우유
초보입니다학교서 수업듣고 있는데연결리스트로 구현된 리스트 ADT 테스트 프로그램을 짜는건데요일단 책에 있는걸 그대로 써서 프로그램 돌려보라고 교수님꼐서 그러셨는데그대로 타이핑해 해봤는데 오류가 엄청 뜨더라구요...좀 봐주실수있나요ㅜㅜ부탁드립니다. #includestdio.h
#includemalloc.h
#includestdlib.h
#includelimits.h #define FALSE 0
#define TRUE 1 typede fint element;
typedef struct ListNode{
element data;
struct ListNode *link;
}ListNode;
typedef struct{
ListNode *head; //헤드포인터
int length; //노드의개수
}LinkedListType; void error(char *message){
fprintf(stderr,%s\n, message);
exit(1); }
void insert_node(ListNode **phead, ListNode *p, ListNode *new_node){
if(*phead == NULL){
new_node-link = NULL;
*phead = new_node;
}
else if(p == NULL){
new_node-link = *phead;
*phead = new_node;
}
else{
new_node-link = p-link;
p-link = new_node;
}} void remove_node(ListNode **phead, ListNode *p, ListNode *removed){
if(p == NULL)
*phead = (*phead)-link;
else
p-link = removed-link;
free(removed);
} //리스트안에서pos 위치의노드를반환한다. ListNode *get_node_at(LinkedListType *list, int pos){
int i;
ListNode *tmp_node = list-head;
if(pos0) return NULL;
for(i=0; ipos; i++)
tmp_node = tmp_node-link;
return tmp_node;
} //리스트의항목의개수를반환한다. int get_length(LinkedListType *list){
return list-length;
} //주어진위치에데이터를삽입한다. void add(LinkedListType *list, int position, element data){
ListNode *p;
if((position = 0) && (position = list-length)){
ListNode*node= (ListNode *)malloc(sizeof(ListNode));
if(node == NULL)error();
node-data = data;
p = get_node_at(list,position-1);
insert_node(&(list-head),p,node);brode);
list-length++;
}
} //리스트의끝에데이터를삽입한다.
void add_last(LinkedListType *list, element data){
add(list, get_length(list), data);
} //리스트의앞에데이터를삽입한다.
void add_first(LinkedListType *list, element data){
add(list, 0, data)
} int is_empty(LinkedListType *list){
if(list-head == NULL) return 1;
else return 0;
}
//주어진위치의데이터를삭제한다. void delete_(LinkedListType *list, int pos){
if(is_empty(list) && (pos = 0) && (pos list-length)){
ListNode *p = get_node_at(list, pos-1);
remove_node(&(list-head),p,(p!=NULL)?p-link:NULL);
list-length--;
}
} element get_entry(LinkedListType *list, int pos){
ListNode *p;
if(pos = list-length)error(위치);
p = get_node_at(list, pos);
return p-data;
} void clear(LinkedListType *list){
int i;
for(i=0; ilist-length; i++)
delete(list,i);
} //버퍼의내용을출력한다. void display(LinkedListType *list){
int i;
ListNode *node=list-head;
printf(();
for(i=0; ilist-length; i++){
printf(%d,node-data);
node = node-link;
}
printf()\n);
} //데이터값이s인노드를찾는다. int is_in_list(LinkedListType *list, element item){
ListNode *p;
p = list-head;
while( (p != NULL) ){
if( p-data == item )
break;
p = p-link;
}
if(p == NULL) return FALSE;
else return True;
}//리스트를초기화한다. void init(LinkedListType *list){
if(list == NULL) return;
list-length = 0;
list-head = NULL;
} int main(){
LinkedListType list1;
init(&list1);
add(&list1, 0, 20);
add_last(&list1, 30);
add_first(&list1, 10);
add_last(&list1, 40);
display(&list1); delete(&list1, 3);
display(&list1);
delete(&list1, 0);
display(&list1);
printf(%s\n, is_in_list(&list1, 20)==true ? 성공: 실패);
printf(%d\n, get_entry(&list1, 0));
}
-
잎새
빌드해보면 어느 라인에 에러 있는지 출력되는데...
해당 라인 부근의 코드에서 문법 오류나 오타난 것이 아닌지 잘 살펴보세요.
어짜피 책 소스 보고 타이핑한 것이면 해당 라인 부근의 책 소스와 본문 소스 코드와 비교하면 되겠네요.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2695766 | 달팽이 배열 어디서 틀렸는지 모르겠습니다ㅠㅠ | 연분홍 | 2025-05-23 |
2695738 | fopen과fclose질문~~ (5) | 희선 | 2025-05-23 |
2695707 | 3의 배수 나타내기. (2) | 수리 | 2025-05-23 |
2695626 | 피보나치수열 과제 때문에 질문 드립니다. (6) | 옆집언니 | 2025-05-22 |
2695595 | 포인트공부중입니다 int형에서 4=1 인가요? (3) | 족장 | 2025-05-22 |
2695567 | 드라이브 고유번호를 가져오는 함수 (2) | 초코맛사탕 | 2025-05-21 |
2695533 | 음수의 산술변환! 질문이요 ㅠㅠ... (4) | 꽃여름 | 2025-05-21 |
2695506 | 구조체 배열 이용 도서목록 출력 프로그램 (1) | 가을귀 | 2025-05-21 |
2695450 | c언어 함수 질문이요.... | 이슬비 | 2025-05-20 |
2695403 | VirtualAlloc함수 및 메모리 질문 | 크리에이터 | 2025-05-20 |
2695355 | c언어 for함수 | 미쿡 | 2025-05-19 |
2695327 | 안녕하세요 제가 이번에 좀 큰 프로그램을.. | 악당 | 2025-05-19 |
2695295 | mutex동기화의 thread기반 채팅 서버소스 질문입니다 | 그루터기 | 2025-05-19 |
2695270 | 질문이요..swap 관한겁니다..ㅠㅠ (3) | 콩알녀 | 2025-05-19 |
2695244 | 노땅초보궁금한게 하나 있는데요..반복문(while문)초보자질문 (6) | 큰꽃늘 | 2025-05-18 |
2695166 | do while 문 어떤것이잘못된건지 모르겠어요 (2) | 아이폰 | 2025-05-18 |
2695122 | 구조체에 대해 물어보고 싶은게 있습니다 ^^^.. (7) | 수련 | 2025-05-17 |
2695091 | txt 파일 입출력 후 2차 배열에 저장하기입니다. (3) | 헛장사 | 2025-05-17 |
2695063 | 수도요금 프로그램좀 짜주세요. | 시내 | 2025-05-17 |
2695033 | 답변좀요ㅠㅠ (1) | 비사벌 | 2025-05-16 |