더블 링커드 리스트에 대한 질문입니다.
집1어치워
프로그램에 오류와 경고는 없으나 프로그램이 실행되지 않네요.질문 요약 :프로그램에 오류와 경고는 없으나 프로그램이 실행되지 않네요.질문 내용 :
DoubleLinked.h
===================================================
#pragma once
//구조체의 정의
typedef struct _NODE
{
char data;
struct _NODE* prev, * next;// 다음과 이전의 멤버를 설정.
}
NODE;
typedef struct
{
NODE* pHead, * pTail; // 머리와 꼬리의 구분.
}
DOUBLE_LIST;
NODE* makeNode(char data);
void addHead(DOUBLE_LIST* pList, char data);
void addTail(DOUBLE_LIST* pList, char data);
void removeHead(DOUBLE_LIST* pList);
void removeTail(DOUBLE_LIST* pList);
void printNormal(DOUBLE_LIST* pList);
void printReverse(DOUBLE_LIST* pList);
char getHead(DOUBLE_LIST* pList);
char getTail(DOUBLE_LIST* pList);
int isEmpty(DOUBLE_LIST* pList);
===================================================
DoubleLinked.c
===================================================
#include stdio.h
#include stdlib.h
#include DoubleLinked.h
NODE* makeNode(char data)
{
NODE* node = malloc(sizeof(NODE));
node-data = data;
node-prev = node-next = NULL;
return node;
}
void addHead(DOUBLE_LIST* pList, char data)
{
NODE* node = makeNode(data); // 새로운 노드를 추가시키는 node.
if(isEmpty(pList) == 1) // pList가 비어있다면 참(1)으로 반환. 비어있지않다면 거짓(0)으로 반환시킨다.
{
pList-pHead = pList-pTail = node;
}
else
{
node-prev = NULL;
node-next = pList-pHead;
pList-pHead-prev = node;
pList-pHead = node;
}
}
void addTail(DOUBLE_LIST* pList, char data)
{
NODE* node = makeNode(data); //
if(isEmpty(pList) == 1)
{
pList-pHead = pList-pTail = node;
}
else
{/nbsp;{
node-prev = pList-pHead;
node-next = NULL;
pList-pTail-next-prev = node;
pList-pTail = node;
}
}
void removeHead(DOUBLE_LIST* pList)
{
if(pList-pHead != NULL)
{
NODE* del = pList-pHead;
if(pList-pHead == pList-pTail)
{
pList-pHead = pList-pTail = NULL;
}
else
{
pList-pHead-next-prev = NULL;
pList-pHead = pList-pHead-next;
}
free(del);
}
}
void removeTail(DOUBLE_LIST* pList)
{
if(pList-pTail != NULL)
{
NODE* del = pList-pTail;
if(pList-pHead == pList-pTail)
{
pList-pHead = pList-pTail = NULL;
}
else
{
pList-pTail-prev-next = NULL;
pList-pTail = pList-pTail-prev;
}
free(del);
}
}
void printNormal(DOUBLE_LIST* pList)
{
NODE* cur;
for(cur = pList-pHead; cur!=NULL;cur=cur-next)
printf(%c, cur-data);
printf(\n);
}
void printReverse(DOUBLE_LIST* pList)
{
NODE* cur;
for(cur = pList-pTail; cur != NULL;cur=cur-prev)
printf(%c, cur-data);
printf(\n);
}
char getHead(DOUBLE_LIST* pList)
{
return pList-pHead-data;
}
char getTail(DOUBLE_LIST* pList)
{
return pList-pTail-data;
}
int isEmpty(DOUBLE_LIST* pList)
{
return pList-pHead == NULL;
}
===================================================
DoubleLinkedMain.c
===================================================
#pragma warning(disable:4996)
#include stdio.h
#include DoubleLinked.h
void main(void)
{
//선언
DOUBLE_LIST list = { 0 };
char s1[] = BLACK,
s2[] = WHITE;
int i;
//추가
printf(** 원본 **\n);
for(i=0;i5;i++)
{
addHead(&list, s1[i]);
addTail(&list, s2[i]);
}
//읽기
printNormal(&list);
printReverse(&list);
printf(머리: %c\n, getHead(&list));
printf(꼬리: %c\n, getTail(&list));
//삭제
printf(\n** 양끝에서 3문자씩 삭제 **\n);
for(i=0;i3;i++)
{
removeHead(&list);
removeTail(&list);
}
printNormal(&list);
printReverse(&list);
printf(머리: %c\n, getHead(&list));
printf(꼬리: %c\n, getTail(&list));
}
===================================================
어느 부분이 잘못 되었는지.. 지적 해주셨으면 합니다.;
잘 부탁드립니다;
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
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 |
2691393 | UNIX 시스템을 사용하려면 어떤 프로그램이 좋을까요? (5) | 든솔 | 2025-04-13 |