리스트로 구현한 원형큐..
오늘 류현진 경기가 비로 취소가 되었고...
주말인데 비가 온다..
요즘 제때 LOL을 못하고 있다..
#include<iostream>
#include<conio.h>
using namespace std;
class CircleQueueNode
{
public:
int data;
CircleQueueNode* link;
public:
CircleQueueNode(int num=0)
{
data=num;
}
};
class CircleQueue
{
public:
int CurrentCount;
CircleQueueNode* rear;
CircleQueueNode* front;
public:
CircleQueue()
{
CurrentCount=0;
rear=NULL;
front=NULL;
}
void EnQue(CircleQueueNode node)
{
CircleQueueNode* Newnode;
Newnode=new CircleQueueNode;
*Newnode=node;
Newnode->link=NULL;
if(CurrentCount==0)
{
rear=Newnode;
front=Newnode;
}
else
{
rear->link=Newnode;
rear=Newnode;
}
CurrentCount++;
}
void DeQue()
{
CircleQueueNode* temp;
if(CurrentCount>1)
{
temp=front;
front=front->link;
cout << "디큐 데이터" << " " << temp->data << endl;
temp->link=NULL;
delete temp;
temp=NULL;
}
else if(CurrentCount==1)
{
temp=front;
cout << "디큐 데이터" << " " << temp->data << endl;
front=NULL;
rear=NULL;
delete front;
delete rear;
}
else
{
cout << "데이터가 없습니다" << endl;
}
CurrentCount--;
}
void ShowAllData()
{
CircleQueueNode* temp;
temp=front;
for(int i=0;i<CurrentCount;i++)
{
cout << i << "번째" << "데이터" << " " << temp->data << endl;
temp=temp->link;
}
}
};
int main()
{
CircleQueueNode a(1), b(2), c(3), d(4);
CircleQueue que;
que.EnQue(a);
que.EnQue(b);
que.ShowAllData();
que.EnQue(c);
que.EnQue(d);
que.ShowAllData();
que.DeQue();
que.ShowAllData();
que.DeQue();
que.DeQue();
que.EnQue(a);
que.ShowAllData();
getch();
return 0;
}