수다닷컴

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

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

캔서

2023.04.01


질문 제목 : 링크드리스트라는 개념을 배우는데... 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

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

  • 횃불

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

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

  • 로와

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

번호 제 목 글쓴이 날짜
2699555 c언어 다항식을 입력을 했는데 왜 출력이 안될까요? 피스케스 2025-06-27
2699528 C언어 포인터연산 질문입니다. (3) 안녕나야 2025-06-26
2699476 끌어올림;;달력 짜봤는데요 이 소스 줄일 수 있나요? - 스샷첨부 (2) 클라우드 2025-06-26
2699444 [좀 급함] system("explorer [주소] ") 문에 변수를 사용할 수 있나요? 알 2025-06-26
2699415 파일//read//와 배열 아란 2025-06-25
2699386 구조체 안에 일부분만 char 배열에 복사하려면 어떻게 해야하나요? (1) 미즈 2025-06-25
2699361 연결리스트 정렬하는 부분에 대해서 질문 드립니다 아이처럼 2025-06-25
2699304 [기초]아직 안주무시는분 계신가요..?포인터배열? 좀 도와주세요. 놀리기 2025-06-24
2699272 printf() 함수이용해서 프로그램 만들기 질문요! (5) 다가 2025-06-24
2699221 PUSH와 POP코드를 더 간단하게 어떻게 해야할까요? 파라미 2025-06-24
2699192 설치오류가 자꾸 나요 한번봐주세여~ (1) 소녀틳향기 2025-06-23
2699161 for loop안에 있는 if문 (9) Orange 2025-06-23
2699105 링크더리스트 이전 링크값 출력함수. 꼬꼬마 2025-06-23
2699078 정수를 한자리씩 배열에 담는 법은 어떻게 하나요.. (4) 귀염포텐 2025-06-22
2699024 C언어 공부하려는데 도와주세요!!! (2) 달님 2025-06-22
2698994 날짜 계산하는 C 코드 짜고 있는데 꽉 막혀서 질문드립니다.. (6) 별 2025-06-22
2698967 파일삭제 윈도우 폴더까지 접근하게하는 함수가 뭔가요 (2) 샤인 2025-06-21
2698938 c언어 메모리질문 (3) 나래 2025-06-21
2698909 서비스 요청 고객 관리 프로그램 짜는것좀 도와주세요ㅜㅜ (4) 궁수자리 2025-06-21
2698882 프로그래밍좀 짜주세요 (3) 황예 2025-06-21
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

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