노드 추가하기 (소스 있어요 ㅇ.ㅇ)
꽃가람
질문 제목 : 노드 추가하기아래 소스에서 연결리스트 노드 구조에 항목을 더 추가하고 삽입하기질문 내용 :아래에 진한 글씨 부분 ㅇ.ㅇ 봐주세요
#include stdio.h
#include stdlib.h
#include string.htypedef struct listnode {
char data[20]; //이곳에 int score, char grade를 추가
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 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){ //삽입함수부분listnode* newnode;
listnode* p;
newnode = (listnode*)malloc(sizeof(listnode));
strcpy(newnode-data, x);
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, p-data);
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, 월);
addlastnode(l, 수);
addlastnode(l, 금);
printlist(l); getchar();printf((3) 리스트 마지막에 1개의 노드 추가하기! \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();
retubsp;return 0;
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2698012 | 2~9가아닌수 | 아놀드 | 2025-06-13 |
2697980 | for에 gets함수를 넣으니까 왜 반복이 안되죠 ㅜ (2) | 펴라 | 2025-06-12 |
2697952 | 2차배열과 함수문의^^; | VanilLa | 2025-06-12 |
2697924 | 다차원 배열 질문있습니다 | 두동 | 2025-06-12 |
2697893 | 정올 :: 기초다지기 a9007 배열7 (문제가 이상함 -_-) | 흰두루 | 2025-06-12 |
2697862 | Unable......... 지정된 파일을 찾을 수 없습니다!! (1) | Creator | 2025-06-11 |
2697761 | 그러니까여제말은... (2) | 새론 | 2025-06-10 |
2697737 | 정올 문제좀 풀어보신분~ | 레오 | 2025-06-10 |
2697709 | rand함수 질문좀요! (6) | 가막새 | 2025-06-10 |
2697683 | C언어 변수뒤 표시가 이해안되는게 있습니다. | 소미 | 2025-06-10 |
2697660 | 껍데기딜 만들고 난후 어느핫키 누르면 코드검색이라도 뜨고 그다음 무반응 해결좀 (2) | 움찬 | 2025-06-09 |
2697634 | c언어로 감성사전 만들기! (1) | 도란도란 | 2025-06-09 |
2697605 | 이 함수좀... | agine | 2025-06-09 |
2697574 | 배열 기본적인질문 (3) | 민트향 | 2025-06-09 |
2697549 | 배열 초기화 (4) | 나리 | 2025-06-08 |
2697465 | 수다님...^^ (2) | 가론 | 2025-06-08 |
2697432 | 서버 만드는 함수에서 궁금한게있어요~ | 파랑 | 2025-06-07 |
2697401 | 열혈강의 문제오류 (1) | 꿈 | 2025-06-07 |
2697374 | 기초적인 C언어 프로그래밍 입니다. | 얼 | 2025-06-07 |
2697341 | 좌우대칭 문제인데 Q가 입력되면 종료가 되야하는데 되지않습니다 | 무지개 | 2025-06-07 |