#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int iData;
struct node *npLink;
} NODE;
typedef struct queue
{
int iCount;
struct node *npFront;
struct node *npRear;
} QUEUE;
void insertQueue(QUEUE *qpQ, int iInData);
int deleteQueue(QUEUE *qpQ);
void printQeueu(QUEUE *qpQ);
int main()
{
QUEUE *qpQueue = (QUEUE*)malloc(sizeof(QUEUE));
qpQueue->iCount = 0;
qpQueue->npFront = NULL;
qpQueue->npRear = NULL;
insertQueue(qpQueue, 1);
printf("데이터의 갯수 : %d\n", qpQueue->iCount);
insertQueue(qpQueue, 2);
printf("데이터의 갯수 : %d\n", qpQueue->iCount);
insertQueue(qpQueue, 3);
printf("데이터의 갯수 : %d\n", qpQueue->iCount);
printQeueu(qpQueue);
printf("나온값은 : %d\n", deleteQueue(qpQueue));
printf("데이터의 갯수 : %d\n", qpQueue->iCount);
printQeueu(qpQueue);
insertQueue(qpQueue, 4);
printQeueu(qpQueue);
printf("나온값은 : %d\n", deleteQueue(qpQueue));
printf("데이터의 갯수 : %d\n", qpQueue->iCount);
printf("나온값은 : %d\n", deleteQueue(qpQueue));
printf("데이터의 갯수 : %d\n", qpQueue->iCount);
printQeueu(qpQueue);
printf("나온값은 : %d\n", deleteQueue(qpQueue));
printf("데이터의 갯수 : %d\n", qpQueue->iCount);
printQeueu(qpQueue);
return 0;
}
void insertQueue(QUEUE *qpQ, int iInData)
{
NODE *npNewNode = (NODE*)malloc(sizeof(NODE));
npNewNode->iData = iInData;
npNewNode->npLink = NULL;
if (qpQ->iCount == 0)
{
qpQ->npFront = npNewNode;
qpQ->npRear = npNewNode;
}
else
{
qpQ->npRear->npLink = npNewNode;
qpQ->npRear = npNewNode;
}
qpQ->iCount++;
}
int deleteQueue(QUEUE *qpQ)
{
NODE *npCurNode = NULL;
int iReData;
if (qpQ->iCount == 0)
{
printf("No Data!\n");
exit(1);
}
else
{
npCurNode = qpQ->npFront;
iReData = npCurNode->iData;
qpQ->npFront = npCurNode->npLink;
free(npCurNode);
qpQ->iCount--;
return iReData;
}
}
void printQeueu(QUEUE *qpQ)
{
NODE *npCurNode = NULL;
if (qpQ->iCount == 0)
{
printf("No Data!\n");
exit(1);
}
else
{
npCurNode = qpQ->npFront;
while (npCurNode != NULL)
{
printf("%d => ", npCurNode->iData);
npCurNode = npCurNode->npLink;
}
printf("NULL\n");
}
}
'IT 전공지식 > 자료구조(Data Structure)' 카테고리의 다른 글
linked list 정렬입력 (0) | 2014.11.14 |
---|---|
linked list (0) | 2014.11.14 |
circular queue (0) | 2014.11.07 |
배열 스택 (0) | 2014.10.24 |
서브스트링 연산 (0) | 2014.10.23 |