디시인사이드 갤러리

갤러리 이슈박스, 최근방문 갤러리

갤러리 본문 영역

우선순위 큐 에러 질문 좀 드립니다

학교에서뭘배(175.112) 2010.12.07 17:36:32
조회 77 추천 0 댓글 3

#ifndef PRIORITYQUEUE_H
#define QEIORITYQUEUE_H

#include<stdio.h>
#include<stdlib.h>
#include<memory.h>

typedef int PriorityType;

typedef struct tagPQNode
{
 PriorityType Priority;
 void* Data;
} PQNode;

typedef struct tagPriorityQueue
{
 PQNode* Nodes;
 int Capacity;
 int UsedSize;
} PriorityQueue;

PriorityQueue* PQ_Create( int InitialSize );
void PQ_Destroy( PriorityQueue* PQ );
void PQ_InQueue( PriorityQueue* PQ, PQNode NewData );
void PQ_DeQueue( PriorityQueue* PQ, PQNode* Root );
int PQ_GetParent( int Index );
int PQ_GetLeftChild( int Index );
void PQ_SwapNodes( PriorityQueue* PQ, int Index1, int Index2 );
void PQ_IsEmpty( PriorityQueue* PQ );

#endif

-----------------------------------------------------------------------

#include"PriorityQueue.h"

PriorityQueue* PQ_Create( int InitialSize )
{
 PriorityQueue* PQ = (PriorityQueue*)malloc( sizeof(PriorityQueue*) );

 PQ->Capacity = InitialSize;
 PQ->UsedSize = 0;
 
 PQ->Nodes = (PQNode*)malloc( sizeof(PQNode) * PQ->Capacity );

 return PQ;
}

void PQ_Destroy( PriorityQueue* PQ )
{
 free( PQ->Nodes );
 free( PQ );
}

void PQ_InQueue( PriorityQueue* PQ, PQNode NewData )
{
 int CurrentPosition = PQ->UsedSize;
 int ParentPosition  = PQ_GetParent( PQ->UsedSize );

 if( PQ->UsedSize == PQ->Capacity )
 {
  if( PQ->Capacity == 0 )
   PQ->Capacity = 1;

  PQ->Capacity *= 2;
  
  PQ->Nodes = (PQNode*)realloc( PQ->Nodes, sizeof(PQNode) * PQ->Capacity );
 }

 PQ->Nodes[CurrentPosition] = NewData;

 while( CurrentPosition > 0 && PQ->Nodes[CurrentPosition].Priority < PQ->Nodes[ParentPosition].Priority )
 {
  PQ_SwapNodes( PQ, CurrentPosition, ParentPosition );

  CurrentPosition = ParentPosition;
  ParentPosition  = PQ_GetParent( CurrentPosition );
 }

 PQ->UsedSize++;
}

void PQ_DeQueue( PriorityQueue* PQ, PQNode* Root )
{
 int ParentPosition = 0;
 int LeftPosition   = 0;
 int RightPosition  = 0;

 memcpy( Root, &PQ->Nodes[0], sizeof(PQNode) );
 memset( &PQ->Nodes[0], 0, sizeof(PQNode) );

 PQ->UsedSize--;

 LeftPosition  = PQ_GetLeftChild( ParentPosition );
 RightPosition = LeftPosition + 1;

 while( 1 )
 {
  int SelectChild = 0;

  if( LeftPosition >= PQ->UsedSize )
   break;

  if( RightPosition >= PQ->UsedSize )
   SelectChild = LeftPosition;
  else
  {
   if( PQ->Nodes[LeftPosition].Priority > PQ->Nodes[RightPosition].Priority )
    SelectChild = RightPosition;
   else
    SelectChild = LeftPosition;
  }

  if( PQ->Nodes[ParentPosition].Priority > PQ->Nodes[SelectChild].Priority )
  {
   PQ_SwapNodes( PQ, ParentPosition, SelectChild );
   SelectChild = ParentPosition;
  }
  else
   break;

  LeftPosition  = PQ_GetLeftChild( ParentPosition );
  RightPosition = LeftPosition + 1;
 }

 if( PQ->UsedSize < ( PQ->Capacity / 2 ) )
 {
  PQ->Capacity /= 2;
  
  PQ->Nodes = (PQNode*)realloc( PQ->Nodes, sizeof(PQNode) * PQ->Capacity );
 }
}

int PQ_GetParent( int Index )
{
 return ( ( Index - 1 ) / 2 );
}

int PQ_GetLeftChild( int Index )
{
 return ( ( Index * 2 ) + 1 );
}

void PQ_SwapNodes( PriorityQueue* PQ, int Index1, int Index2 )
{
 int CopySize = sizeof(PQNode);
 PQNode* Temp = (PQNode*)malloc(CopySize);

 memcpy( Temp,               &PQ->Nodes[Index1], CopySize );
 memcpy( &PQ->Nodes[Index1], &PQ->Nodes[Index2], CopySize );
 memcpy( &PQ->Nodes[Index2], Temp,               CopySize );

 free(Temp);
}

void PQ_IsEmpty( PriorityQueue* PQ )
{
 return ( PQ->UsedSize == 0 );
}

-------------------------------------------------------------------------------


#include"PriorityQueue.h"

void PrintNode( PQNode* Node )
{
 printf("작업명 : %s (우선순위:%d)\\n", Node->Data, Node->Priority);
}

int main(void)
{
 PriorityQueue* PQ = PQ_Create( 3 );
 PQNode Popped;

 PQNode Nodes[7] =
 {
  (34, (void*)"코딩"),
  (12, (void*)"고객미팅"),
  (87, (void*)"커피타기"),
  (45, (void*)"문서작성"),
  (35, (void*)"디버깅"),
  (66, (void*)"이닦기"),
 };

 PQ_EnQueue( PQ, Nodes[0] );
 PQ_EnQueue( PQ, Nodes[1] );
 PQ_EnQueue( PQ, Nodes[2] );
 PQ_EnQueue( PQ, Nodes[3] );
 PQ_EnQueue( PQ, Nodes[4] );
 PQ_EnQueue( PQ, Nodes[5] );

 printf( "큐에 남아 있는 작업의 수 : %d\\n", PQ->UsedSize );

 while( !PQ_IsEmpty( PQ ) )
 {
  PQ_DeQueue( PQ, &Popped );
  PrintfNode( &Popped );
 }

 return 0;
}


요약을 하자면

마지막

while( !PQ_IsEmpty( PQ ) )
 {
  PQ_DeQueue( PQ, &Popped );
  PrintfNode( &Popped );
}

에서 에러가 나네요 에러 내용을 보자면

오류 5 error C2171: \'!\' : \'void\' 형식의 피연산자에는 맞지 않습니다. 
오류 6 error C2180: 제어 식의 형식이 \'void\'입니다. 

이정도인데요 Data형을 (void*) 했는거랑 관계 있을까요

추천 비추천

0

고정닉 0

0

댓글 영역

전체 댓글 0
등록순정렬 기준선택
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 가족과 완벽하게 손절해야 할 것 같은 스타는? 운영자 24/06/24 - -
236567 자바에 대해 뭘 좀 알려면 이책을 보라 SODmaster갤로그로 이동합니다. 11.03.02 92 0
236566 형들아.. 질문이 있는데요, 정보보안전문가 되려면 어떻게 해요? [2] Minryu갤로그로 이동합니다. 11.03.02 180 0
236565 왜 각 대학마다... 슈ㅣ발닭(112.133) 11.03.02 68 0
236564 민류 까지 말라능 [17] 분당살람갤로그로 이동합니다. 11.03.02 176 0
236563 [중앙정보보안아카데미] 웹 접근성 강화를 위한 웹 표준기술 개강안내 [1] gumpkim(125.129) 11.03.02 57 0
236562 [내일배움카드제] 3월 국비지원 내일배움카드제(계좌제) 개설과목 안내 [1] gumpkim(125.129) 11.03.02 45 0
236561 상위권 대학 편입은... [6] 슈ㅣ발닭(112.133) 11.03.02 131 0
236560 재보선에 엄기영 나오네 [1] 이모군(1.225) 11.03.02 70 0
236559 연세대 편입에 대해 알아보았다.. [1] 연세대닭(112.133) 11.03.02 223 0
236557 대학왔으니 질문글올림 [5] 마루■갤로그로 이동합니다. 11.03.02 141 0
236556 [내일배움카드제] 3월 국비지원 내일배움카드제(계좌제) 개설과목 안내 [1] gumpkim(125.129) 11.03.02 47 0
236554 형들아 부탁점...... [1] SODmaster갤로그로 이동합니다. 11.03.02 64 0
236553 이제 개강하면 질문글 엄청올라오겠구나 [1] 꿀레(14.33) 11.03.02 79 0
236552 C++질문 있어요...(과제 아닙니다.) [5] 블러디갤로그로 이동합니다. 11.03.02 175 0
236551 SW 기술자 신고제 폐지 됀냐? [1] ltw갤로그로 이동합니다. 11.03.02 173 0
236549 어머나 세상에, 아직도 민류가 암컷인줄 아는 사람들이 있단말야? [10] Minryu갤로그로 이동합니다. 11.03.02 229 0
236547 분당살람 횽은 봄.니.다. [2] 물속의다이아갤로그로 이동합니다. 11.03.02 89 0
236546 요즘 회사에서 영어 회화 수업을 하는데... [5] 물속의다이아갤로그로 이동합니다. 11.03.02 188 0
236545 아흑 시간표를 잘못 봐따 ㅠㅠ [2] 일광면(119.198) 11.03.02 87 0
236544 횽들 후로그래밍할 노트북하나만 추전해줘요~~ [1] (114.204) 11.03.02 113 0
236543 곰들, 밍류 암컷인증이냐;; [3] 계백(61.255) 11.03.02 144 0
236542 양요섭 사진 [2] 곰들\'ⓧ\'갤로그로 이동합니다. 11.03.02 195 0
236541 양요섭 멋이따. [2] Minryu갤로그로 이동합니다. 11.03.02 114 0
236540 자, 무섭지 않아. [1] ㅁㄴㄻㄹ갤로그로 이동합니다. 11.03.02 103 0
236539 플갤 형님들 주무시나요? [3] 릴리위즈덤갤로그로 이동합니다. 11.03.02 105 0
236538 네가 했던 말 기억해? 천재플머(175.196) 11.03.02 83 0
236537 봐, 무섭지 않아. 천재플머(175.196) 11.03.02 77 0
236536 내 이름이 잘 기억나지 않는다. [1] 천재플머(175.196) 11.03.02 62 0
236535 잠이 오지 않아 잠을 설쳤다. 천재플머(175.196) 11.03.02 58 0
236534 vssettings가 들어있는 폴더를 지웠을 경우에는 어떻게 하나요? 질문자(122.39) 11.03.02 695 0
236533 근데 커스텀 커널이 확실히 쾌적하다... [1] 땡칠도사갤로그로 이동합니다. 11.03.02 123 0
236532 아오 빡친당.. -1을 +1로 쓴거 때매.. ㅇㅇ(119.71) 11.03.02 96 0
236531 횽들 나 인턴이 잡고싶은데, 쿠루우우갤로그로 이동합니다. 11.03.02 73 0
236530 백지인간에게 프로그래밍 책 추천해주십시오. [4] 복학생(117.123) 11.03.02 142 0
236529 이번학기 망했다 땡칠도사갤로그로 이동합니다. 11.03.02 97 0
236528 책은.. 아무책이나 봐도 된다.. 헤드퍼건 뭐건간에.. 음...(114.205) 11.03.02 72 0
236527 의식있는 프갤러로써 이 현상 어떄요 [5] ㅇㅇ(121.137) 11.03.02 191 0
236526 앞으로 다가올 클라우드 컴퓨팅이 지금은 어디쓰이남여? [1] 딸기맛_농약갤로그로 이동합니다. 11.03.02 84 0
236525 아프리카 tv 리버싱 하고싶다 [1] 딸기맛_농약갤로그로 이동합니다. 11.03.02 1341 0
236524 멕시카나의 상술에 치를 떤다 [1] 유리한갤로그로 이동합니다. 11.03.01 173 0
236523 주면 먹냐 ? 귤귤이갤로그로 이동합니다. 11.03.01 99 0
236521 제로보드XE 간단한설정좀 도와주실분 박구갤로그로 이동합니다. 11.03.01 73 0
236520 다들 해드퍼스트 디게 강추하내 [3] 음..(58.239) 11.03.01 101 0
236518 C#하고 MFC [3] SODmaster갤로그로 이동합니다. 11.03.01 125 0
236516 C#과 MFC 중에 Directx 로 맵툴을 만드려고 하는데.. [4] 무념무상(211.174) 11.03.01 452 0
236515 형님들 C#과 MFC 중 배워두면 나중에 더 잘 써먹는 것이 어느것일까요 [9] 무념무상(211.174) 11.03.01 147 0
236514 c++은 어떤교재가 좋져? [10] asd(125.137) 11.03.01 134 0
236512 올해 3학기짼대 사야할책이 .. [16] 트윗덱갤로그로 이동합니다. 11.03.01 224 0
236511 vb(비주얼베이직6.0) sql 호환하는 방법 좀 알려주세요. [2] 번개번개갤로그로 이동합니다. 11.03.01 172 0
236510 헤드퍼스트가 좋은 점 [2] 막장갤신학생갤로그로 이동합니다. 11.03.01 104 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2