수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

링크드리스트에 관해 c언어 수다님들!!! 질문 하나 하겠습니다.!!!

영빈이

2024.03.24


질문 제목 : 링크드리스트라는 개념을 배우는데... c언어의 기본은 알겠는데(알아도 왕초보입니다.)
이 소스를 보고는 도저히 이해가 안 가서 질문합니다.

각 줄이 무엇을 뜻하는지 도저히 모르겠네요.

질문 내용 :소스파일 2개 .c로 된거... 헤더파일 1개 .h로 된거... 비주얼 스튜디오 2008에서 구동했구요.
c언어 수다님들 주석 좀 달아주셨으면 좋겠습니다. 감사합니다.

exampl03_02.c 파일

#include stdio.h
#include stdlib.h
#include linkedlist.h
void displaylinkedlist(linkedlist* plist)
{
int i = 0;
if (plist != null) {
printf(현재 원소 개수: %d\n, plist-currentelementcount);
for(i = 0; i plist-currentelementcount; i++) {
printf([%d],%d\n, i, getllelement(plist, i)- data);
}
}
else {
printf(원소가 없습니다.\n);
}
}
int main(int argc, char *argv[])
{
int i = 0;
int arraycount = 0;
linkedlist *plist = null;
listnode* pnode = null;
listnode node;
plist = createlinkedlist();
if (plist != null) {
node.data = 1;
addllelement(plist, 0, node);
node.data = 3;
addllelement(plist, 1, node);
node.data = 5;
addllelement(plist, 2, node);
displaylinkedlist(plist);
removellelement(plist, 0);
displaylinkedlist(plist);
deletelinkedlist(plist);
}
return 0;
}

linkedlist.c 파일

#include stdio.h
#include stdlib.h
#include string.h
#include linkedlist.h
linkedlist* createlinkedlist()
{
linkedlist *preturn = null;
int i = 0;
preturn = (linkedlist *)malloc(sizeof(linkedlist));
if (preturn != null) {
memset(preturn, 0, sizeof(linkedlist));
}
else {
printf(오류, 메모리할당 createlinkedlist()\n);
return null;
}
return preturn;
}
int addllelement(linkedlist* plist, int position, listnode element)
{
int ret = false;
int i = 0;
listnode* pprenode = null;
listnode* pnewnode = null;
if (plist != null) {
if (position = 0
&& position = plist - currentelementcount) {
pnewnode = (listnode*)malloc(sizeof(listnode));
if (pnewnode != null) {
*pnewnode = element;
pnewnode-plink = null;
pprenode = &(plist-headernode);
for(i = 0; i position; i++) {
pprenode = pprenode-plink;
}
pnewnode-plink = pprenode - plink;
pprenode - plink = pnewnode;
plist- currentelementcount++;
ret = true;
}
else {
printf(오류, 메모리할당 addllelement()\n);
return ret;
}
}
else {
printf(오류, 위치 인덱스-[%d], addllelement()\n, position);
}
}
return ret;
}
int removellelement(linkedlist* plist, int position)
{
int ret = false;
int i = 0;
int arraycount = 0;
listnode* pnode = null;
listnode* pdelnode = null;
if (plist !=plist != null) {
arraycount = getlinkedlistlength(plist);
if (position = 0 && position arraycount)
{
pnode = &(plist - headernode);
for(i = 0; i position; i++) {
pnode = pnode - plink;
}
pdelnode = pnode-plink;
pnode-plink = pdelnode-plink;
free(pdelnode);
plist-currentelementcount--;
ret = true;
}
else {
printf(오류, 위치 인덱스-[%d] removellelement()\n, position);
}
}
return ret;
}
listnode* getllelement(linkedlist* plist, int position)
{
listnode* preturn = null;
int i = 0;
listnode* pnode = null;
if(plist != null) {
if (position =0 && position plist-currentelementcount) {
pnode = &(plist-headernode);
for(i = 0; i = position; i++) {
pnode = pnode-plink;
}
preturn = pnode;
}
}
return preturn;
}
void deletelinkedlist(linkedlist* plist)
{
int i = 0;
if (plist != null) {
clearlinkedlist(plist);
free(plist);
}
}
void clearlinkedlist(linkedlist* plist)
{
if (plist != null) {
if (plist-currentelementcount 0) {
removellelement(plist,0);
}
}
}
int getlinkedlistlength(linkedlist* plist)
{
int ret = 0;
if (plist != null) {
ret = plist - currentelementcount;
}
return ret;
}
int isempty(linkedlist* plist)
{
int ret = false;
if (plist != null) {
if (plist-currentelementcount == 0) {
ret = true;
}
}
return ret;
}

linkedlist.h 파일

#ifndef _linkedlist_
#define _linkedlist_
typedef struct listnodetype
{
int data;
struct listnodetype* plink;
} listnode;
typedef struct linkedlisttype
{
int currentelementcount;// 현재 저장된 원소의 개수
listnode headernode;// 헤더 노드(header node)
} linkedlist;
linkedlist* createlinkedlist();
int addllelement(linkedlist* plist, int position, listnode element);
int removellelement(linkedlist* plist, int position);
listnode* getllelement(linkedlist* plist, int position);
void clearlinkedlist(linkedlist* plist);
int getlinkedlistlength(linkedlist* plist);
void deletelinkedlist(linkedlist* plist);
#endif
#ifndef _common_list_def_
#define _common_list_def_
#define true1
#define false0
#endif

실행 화면

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

  • 가을 2024-03-24

    일단 질문자체부터... 이렇게 올리는건 숙제 좀 해달라는 것과 비견댈 정도의 질문이네요..-_-;;
    \난 아무것도 모르겠으니, 대신 좀 해주시죠?\ 라는 말과 다를바가 없습니다.
    적어도 자신이 아는 범위는 어느정도 이며, 어느부분이 잘 이해가 안가는지 스스로 알아야 질문도 체계적으로 할 수 있습니다.

    전혀 모른다면 윗분 말씀대로 아무리 공부를 해봤자 그저 이리저리 헤매기만 할겁니다.
    아니면 좀 더 간단한 소스를 찾아서 공부하시는게 더 도움이 되실겁니다

  • 소심한녀자 2024-03-24

    알고 계시는 C 언어 기본....의 수준이 어느정도인지 알지 못하면 설명하기도 힘듭니다. 일단 연결리스트를 이해하려면 포인터에 대한 확실한 이해는 기본이구요, 동적 메모리 할당/해제도 왠만큼은 할 줄 알아야 합니다. 그리고 마지막으로 구조체도 알아야 하구요. 제가 열거한 이 세 가지 항목 중 하나라도 미숙하다고 생각되는 부분이 있다면, 연결리스트를 아무리 연구 해 봤자 다차 방정식도 모른채 미/적분을 공부하려는 것과 다르지 않지요.

번호 제 목 글쓴이 날짜
2694590 이 코드가 뭐하는 코드일까요? #2 빵순 2025-05-12
2694559 동적할당으로 배열(2차원열)을 만드는데 있어 그걸 함수화시키는데... (1) 늘솔길 2025-05-12
2694532 네트워크에 관하여... (4) 황소자리 2025-05-12
2694503 프로그램 연산 후 바로 종료되는 현상 (6) Judicious 2025-05-11
2694450 while문질문입니다. (1) 허리품 2025-05-11
2694420 C언어 질문할게요(유니코드,자료형,버퍼,캐스트연산자) 은새 2025-05-11
2694370 내일까진데 함수호출 제발 도와주세요!!!!!!!!!11 들찬 2025-05-10
2694339 putchar()의 괄호 안에 int c=10;로 전에 선언된 c를 넣으면 안되는 이유에서 제가 생각한 것이 그 이유가 되는지 확인하고 싶습니다. (3) 미르 2025-05-10
2694316 이 코드 어디가 잘못되었는지 고수분들 ㅠㅠ (2) 나빛 2025-05-10
2694285 언어 공부하는 과정 좀 추천해주세요! (1) 아빠몬 2025-05-09
2694258 카운터.. 질문입니다. (4) 하늘빛눈망울 2025-05-09
2694229 단순한 질문이요 (8) 여름 2025-05-09
2694202 용돈을 가지고 할 수 있는 일을 여러가지로 출력하는 방법 좀 알려주세요! (2) 미나 2025-05-09
2694145 화면깜빡임을 없애고 싶은데요... (1) 어서와 2025-05-08
2694069 unsigned 질문입니다. 힘차 2025-05-07
2694012 전공 비전공자 개발자 (10) 말글 2025-05-07
2693984 오버로딩이 무엇인가요? (2) 헛매질 2025-05-07
2693956 PlaySound재생이 안됩니다!(C에 음악넣기) 지존 2025-05-06
2693928 &와 *의 사용에 관한 명확한 이해 제나 2025-05-06
2693903 반복문 설명좀요 ㅠㅠ (2) 란새 2025-05-06
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com