바로 우선순위 큐의 헤더,소스,메인 다보자 !
PriorityQueue.h
//
// PriorityQueue.h
// UsefulHeap
//
// Created by 서희찬 on 2021/04/11.
//
#ifndef PriorityQueue_h
#define PriorityQueue_h
#include "UsefulHeap.h"
typedef Heap PQueue;
typedef HData PQData;
void PQueueInit(PQueue * ppq, PriorityComp pc);
int PQIsEmpty(PQueue * ppq);
void PEnqueue(PQueue * ppq, PQData data);
PQData PDequeue(PQueue * ppq);
#endif /* PriorityQueue_h */
PriorityQueue.c
//
// PriorityQueue.c
// UsefulHeap
//
// Created by 서희찬 on 2021/04/11.
//
#include "PriorityQueue.h"
#include "UsefulHeap.h"
void PQueueInit(PQueue * ppq, PriorityComp pc)
{
HeapInit(ppq, pc);
}
int PQIsEmpty(PQueue * ppq)
{
return HIsEmpty(ppq);
}
void PEnqueue(PQueue * ppq, PQData data)
{
HInsert(ppq, data);
}
PQData PDequeue(PQueue * ppq)
{
return HDelete(ppq);
}
PriorityQueueMain.c
//
// main.c
// UsefulHeap
//
// Created by 서희찬 on 2021/04/11.
//
#include <stdio.h>
#include "PriorityQueue.h"
int DataPriorityComp(char ch1, char ch2)
{
return ch2 - ch1;
}
int main(void)
{
PQueue pq;
PQueueInit(&pq,DataPriorityComp);
PEnqueue(&pq, 'A');
PEnqueue(&pq, 'B');
PEnqueue(&pq, 'C');
printf("%c \n", PDequeue(&pq));
PEnqueue(&pq, 'A');
PEnqueue(&pq, 'A');
PEnqueue(&pq, 'A');
printf("%c \n",PDequeue(&pq));
while(!PQIsEmpty(&pq))
printf("%c \n", PDequeue(&pq));
return 0;
}