정답을 알고싶어요
무들
질문 제목 : 정답을 알고싶어요질문 내용 :배열로 짜여진 이 프로그램을 포인터로 바꿔보려고 하는데요 정답을 가지고 있지 않아
확인이 불가능 합니다. ㅠㅠㅠ 도와주실분 없으신가요 같이 한번 짜봐주시면 정말 감사하겠습니다.
프로그램 내용은 자식노드와 부모노드로써 목표 노드를 찾는 프로그램입니다.#include stdio.h
#define LIMITL 256
#define TRUE 1
#define START 1
#define GOAL 999
struct node
{
int nodeid;
int parentid;
};
struct node openlist[LIMITL];
int openlistep = 0;
struct node closedlist[LIMITL];
int closedlistep = 0;
void initlist();
void printlist();
void expand(int id);
void movetofirst();
void removefirst();
int check(int id);
void printroute(int id);
int main()
{
initlist();
printlist();
while (TRUE)
{
if (openlistep == 0)
{
printf(목표 노드를 찾을 수 없습니다.\n);
break;
}
if (openlist[0].nodeid == GOAL)
{
printf(\n목표 노드를 찾았습니다.\n);
printf(%d[%d], openlist[0].nodeid,openlist[0].parentid);
printroute(openlist[0].parentid);
break;
}
expand(openlist[0].nodeid);
movetofirst();
printlist();
}
return 0;
}
void printroute(int id)
{
int i;
for (i = 0; i closedlistep; ++i)
if (closedlist[i].nodeid == id)
{
printf(-%d[%d], closedlist[i].nodeid,
closedlist[i].parentid);
break;
}
if (closedlist[i].parentid != 0)
printroute(closedlist[i].parentid);
printf(\n);
}
int check(int id)
{
int i;
int res = 0;
for (i = 0; i openlistep; ++i)
if (openlist[i].nodeid == id)
res = TRUE;
for (i = 0; i closedlistep; ++i)
if (closedlist[i].nodeid == id)
res = TRUE;
return res;
}
void removefirst()
{
int i;
for (i = 0; i openlistep; ++i)
openlist[i] = openlist[i+1];
--openlistep;
}
void movetofirst()
{
closedlist[closedlistep++] = openlist[0];
removefirst();
}void expand(int id)
{
int tree[][5] =
{
{1, 2, 3, 5},
{2, 4},
{3, 6, 7},
{5, 4, 8},
{6, 5, 7},
{8, 7, 999},
{0} /* 정보의 끝 */
};
int i = 0;
int j;
while (tree[i][0] != 0)
{
if (tree[i][0] == id)
{
for (j = 1; tree[i][j] != 0; ++j)
{
if (check(tree[i][j]) != TRUE)
{
openlist[openlistep].nodeid = tree[i][j];
openlist[openlistep++].parentid = id;
}
}
break;
}
++i;
}
}
void initlist()
{
openlist[0].nodeid = START;
openlist[0].parentid = 0;
++openlistep;
}
void printlist()
{
int i;
printf(\n오픈 리스트 );
for (i = 0; i openlistep; ++i)
printf(%d[%d],, openlist[i].nodeid,
openlist[i].parentid);
printf(\n);
printf(클로즈드 리스트 );
for (i = 0; i closedlistep; ++i)
printf(%d[%d],, closedlist[i].nodeid,
closedlist[i].parentid);
printf(\n);
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
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 |
2693869 | stdio.h 는 왜 쓰는건가요? (1) | 큰꽃들 | 2025-05-06 |
2693842 | 포인터 변수의 주소값끼리 더하는 것에 대해서 질문드립니다. (1) | 진솔 | 2025-05-05 |
2693811 | 소수 출력;;;; | 화이트캣 | 2025-05-05 |
2693788 | 이런 함수는 없나요? (3) | 앤드류 | 2025-05-05 |