/// 우선 포인터가 NULL 가르키는게 왜 오류뜨지;;
되는게 있고 안되는게 있네;;
오류 한 30개 나오는데 실제론 2~3개 잡으면 끝날꺼 같음..
누가 헬프미
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct ListNode{
char data[10];
struct listNode * link;
}listNode;
typedef struct{
listNode * head;
}linkedList_h;
linkedList_h * createLinkedList_h(void);
void freeLinkedList_h(linkedList_h * );
void addLastNode(linkedList_h*,char * );
void reserve(linkedList_h*);
void deleteLastNode(linkedList_h*);
void printList(linkedList_h*);
linkedList_h * createLinkedList_h(void){
linkedList_h * L;
L=(linkedList_h*) malloc (sizeof(linkedList_h));
L->head->NULL;
return L;
}
void addLastNode (linkedList_h* L,char* x){
listNode* newNode;
listNode* p;
newNode= (listNode*) malloc (sizeof(listNode));
strcpy(newNode->data,x);
newNode->link=NULL;
if(L->head == NULL)
L->head = newNode;
return;
}
void reverse(linkedList_h * L){
listNode* p;
listNode* q;
listNode* r;
p=L->head;
q=NULL;
r=NULL;
while(p!=NULL){
r=q;
q=p;
p=p->link;
q->link = r;
}
L->head=q;
}
void deleteLastNode(linkedList_h* L){
listNode * previous;
listNode * current;
if(L->head==NULL) return;
if(L->head->link == NULL){
free(L->head);
L->head = NULL;
return;
}
else{
previous = L->head;
current = L->head->link;
while(current ->link !=NULL){
previous = current;
current = current->NULL;
}
free(current);
previous->link=NULL;
}
}
void freeLinkedList_h(linkedList_h* L){
listNode* P;
while(L->head != NULL){
p=L->head;
L->head = L->head->link;
free(p);
p=NULL;
}
}
void printList(linkedList_h* L){
listNode * p;
printf(\"L = (\");
p=L->head;
while(p !=NULL){
printf(\"%s\",p->data);
p = p->link;
if(p !=NULL){
printf(\",\");
}
}
printf(\")\\n\");
}
int main(){
linkedList_h * L;
L=createLinkedList_h();
printf(\"공백 리스트 생성하기! \\n\");
addLastNode(L,\"월\");
addLastNode(L,\"수\");
addLastNode(L,\"금\");
printList(L); getchar();
printf(\"(3) 리스트 마지막에 노드 한개 추가하기! \\n\");
addLastNode(L,\"일\");
printList(L); getchar();
printf(\"(4) 마지막 노드 삭제하기! \\n\");
deleteLastNode(L);
printList(L); getchar();
printf(\"(5) 리스트의 원소를 역순으로 변환하기! \\n\");
reverse(L);
printList(L); getchar();
printf(\"(6) 리스트 공간을 해제하여, 공백 리스트 상태로 만들기! \\n\");
freeLinkedList_h(L);
printList(L);
getchar();
return 0;
}
다음사람에게 패스!!
NULL 이 필드명임니까?
NULL= 0으로 define 되어있지..
아, 또 하나 잡았다
글 새로 팜
구조체의 필드를 접근할때 어떻게 하나요?
구조체.멤버변수
만약 포인터가 구조체를 가르킨다면
(*포인터).멤버변수 = 포인타->멤버변서