큐를 이용해서 연결리스트를 구성하는 프로그램을 구성했는데...

Chance78의 이미지

학교 과제로 큐를 이용해서 연결리스트를 구성했는데 자꾸 컴파일하면 에러가
뜨네요.. ㅡㅡ. 연결리스트를 구성하는 노드 구조체 부분에서 에러가 뜨는데
아무리 찾아봐도 왜 에러가 뜨는지 모르겠어요.. 아시는 분은 좀 가르켜주시길..

그럼 부탁 드립니다..

#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();
}

urmajest의 이미지

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]

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.