큐를 이용해서 연결리스트를 구성하는 프로그램을 구성했는데...
글쓴이: Chance78 / 작성시간: 목, 2003/06/19 - 4:22오전
학교 과제로 큐를 이용해서 연결리스트를 구성했는데 자꾸 컴파일하면 에러가
뜨네요.. ㅡㅡ. 연결리스트를 구성하는 노드 구조체 부분에서 에러가 뜨는데
아무리 찾아봐도 왜 에러가 뜨는지 모르겠어요.. 아시는 분은 좀 가르켜주시길..
그럼 부탁 드립니다..
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define IS_FULL(ptr) (!(ptr))
#define IS_EMPTY(ptr) (!(ptr))
typedef struct node *listPtr;
struct node {
char data;
listPtr link;
};
listPtr find(listPtr list, char x);
void enqueue(listPtr *front, listPtr *rear, char x);
char dequeue(listPtr *front);
char queue_empty();
void memory_overflow();
void programInfo();
void programMenu();
int selectMenu();
void programEnd();
listPtr endqueue(listPtr *front);
listPtr find(listPtr list, char x);
int main()
{
int menu;
char input;
listPtr list = (listPtr)malloc(sizeof(listPtr));
programInfo();
do {
programMenu();
menu = selectMenu();
switch(menu)
{
case 1: printf("검색할 문자를 입력하세요. : ");
fflush(stdin);
scanf("%c",&input);
if(find(list,input))
{
printf("입력한 문자가 큐에 있습니다.");
fflush(stdin);
getche();
}
else
{
printf("입력한 문자가 큐에 없습니다.");
fflush(stdin);
getche();
}
break;
case 2: printf("큐에 저장할 문자를 입력하세요. : ");
fflush(stdin);
scanf("%c",&input);
enqueue(list,(endqueue(list)),input);
break;
case 3: if( input = dequeue(list))
{
printf("현재 큐의 내용은 %c 입니다. ", input);
fflush(stdin);
getche();
break;
}
break;
case 4: programEnd();
break;
default : break;
}
} while (menu != 4);
return 0;
}
listPtr endqueue(listPtr *front)
{
listPtr end;
end = front;
while(end->link != NULL)
{
end = end->link;
}
return end;
}
listPtr find(listPtr list, char x)
{
listPtr temp;
temp = list;
while((temp != NULL) && (temp->data != x))
temp = temp->link;
if(temp->data == x) return temp;
else return NULL;
}
void enqueue(listPtr *front, listPtr *rear, char x)
{
listPtr temp = (listPtr)malloc(sizeof(front));
if(IS_FULL(temp))
{
memory_overflow();
return;
}
temp->data = x;
temp->link = NULL;
if (*front) (*rear)->link = temp;
else *front = temp;
*rear = temp;
}
char dequeue(listPtr *front)
{
listPtr temp;
char x;
temp = *front;
if(IS_EMPTY(*front)) {
return queue_empty();
}
x = temp->data;
*front = temp->link;
free(temp);
return x;
}
//*************************************************************************//
// 함수 : queue_empty() //
// 기능 : Queue가 비어있다는 에러메시지 출력 후 임의의 키 입력 대기 //
// 내용 : 호출 시 Queue가 비어있다는 메세지 출력 후 임의의 키 입력 대기 //
//*************************************************************************//
char queue_empty()
{
printf("\n\tQueue가 비어있습니다.\n");
getche();
fflush(stdin);
return NULL;
}
//*************************************************************************//
// 함수 : memory_overflow() //
// 기능 : 동적메모리를 생성 할 수 없다는 메세지 출력 //
// 내용 : 메세지 출력 후 임의의 키 입력 대기 //
//*************************************************************************//
void memory_overflow()
{
printf("\n\t새로운 리스트를 생성 할 수 없습니다.");
getche();
fflush(stdin);
}
void programInfo()
{
system("cls");
puts("\n\n\n");
puts("\t----------------------------------------------------------------");
puts("\t수업명 : 자료구조 프로그램이름 : 프로그램 과제 #7 ");
puts("\t학과 : 정보통신공학과 학번 : 200232066 ");
puts("\t학년 : 2학년 이름 : 이 기회 ");
puts("\t----------------------------------------------------------------");
puts("");
puts("\t아무키나 누루세요... ");
getche();
fflush(stdin);
}
//*************************************************************************//
//함수 : programMenu() //
//기능 : 전화번호 메인 메뉴화면 //
//내용 : 화면 clear후 메인 메뉴 출력 //
//*************************************************************************//
void programMenu()
{
system("cls");
fprintf(stdout,"\n\n\n\n");
puts("\t\t\t 큐를 이용한 연결 리스트\n");
puts("\t\t1. 큐 검색\n");
puts("\t\t2. 큐 삽입 \n");
puts("\t\t3. 큐 출력 \n");
puts("\t\t4. 끝 내 기 \n\n");
}
//*************************************************************************//
//함수 : selectMenu() //
//기능 : 입력받은 번호를 리턴 //
//내용 : 메인 메뉴에서 메뉴 선택시 키보드 입력받는 함수 //
//*************************************************************************//
int selectMenu(void)
{
int select;
printf("\t원하시는 번호를 입력하세요. : ");
scanf("%d", &select);
fflush(stdin);
return select;
}
//*************************************************************************//
//함수 : programEnd() //
//기능 : 프로그램 종료시 출력 //
//내용 : 프로그램 종료 선택시 출력 //
//*************************************************************************//
void programEnd()
{
puts("\n\t 큐를 이용한 연결리스트 프로그램을 종료합니다. \n\n");
fflush(stdin);
getche();
}
Forums:


..................
typedef struct node *listPtr; struct node { char data; listPtr link; }; listPtr find(listPtr list, char x); void enqueue(listPtr *front, listPtr *rear, char x);이 부분을 잘 살펴보세요.
'내가 * 붙인 건 뭐고 안 붙인건 뭘까?'
위의 프로그램이 정상적으로 동작하지 않는 이유는,
포인터의 개념을 잘 모르고 작성하셨기 때문입니다.
자료구조 책에는 Queue ADT에 대한 예제는 어떤 책이든 빠지지 않고
나와있죠?
예제와 한번 비교해 보세요
우선 그 전에 pointer에 대해 확실히 짚고 넘어가는게 좋겠죠.
책을 읽읍시다 ^^
[/code]
댓글 달기