연결리스트 간단한 프로그램 질문이요(소스있습니다)
해리
질문 제목 : 연결리스트 간단한 프로그램 질문이요질문 요약 :아래 소스에서 int score에 값 넣기가 너무 어렵네요 진하게 해논 부분 봐주셨으면 좋겠습니다 ㅠ_ㅠ
뭐가 문제인지 잘 모르겠네요 ㅠ.ㅠ질문 내용 :
#include stdio.h
#include stdlib.h
#include string.h
typedef struct listnode {
char data[20];
int score;
char grade[1];
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*, int*, char*);
void reverse(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,int* b, char* y){
listnode* newnode;
listnode* p;
newnode = (listnode*)malloc(sizeof(listnode));
strcpy(newnode-data, x);
newnode-score=b;
strcpy(newnode-grade, y);
newnode-link= null;
if (l-head == null){
l-head = newnode;
return;
}
p = l-head;
while (p-link != null) p = p-link;
p -link = newnode;
}
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-link;
}
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\t, p-data);
printf(%s\t, p-grade);
p = p-link;
if(p!=null) printf(, );
}
printf() \n);
}
int main(){
linkedlist_h* l;
l = createlinkedlist_h();
printf((1) 공백 리스트 생성하기! \n);
printlist(l); getchar();
printf((2) 리스트에 3개의 노드 추가하기! \n);
addlastnode(l, 월, 5, c);
addlastnode(l, 화, 6, b);
printlist(l); getchar();
printf((3) 리스트 마지막에 1개의 노드 추가하기! \n);
addlastnode(l, 일, 7, a);
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;
}
-
가온누리
int 형으로 선언되어있는데 함수로 받기는 int *로 지정 되어있네요.
void addLastNode(linkedList_h* L, char* x,int b, char* y)
요런형태로 가야하지 않을까요?
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |
2691483 | 파일 오픈시 에러 질문드립니다. (2) | 호습다 | 2025-04-14 |
2691450 | [visual c++ 툴]기초 질문 (3) | 해긴 | 2025-04-13 |