1. Queue ¶
- Queueλ λμ€μ λ£μ κ²μ λμ€μ λμ€κ³ λ¨Όμ λ£μ κ²μ λ¨Όμ λμ€λ μλ£ κ΅¬μ‘°μ
λλ€.
- μ μλ λ»₯ λ«λ¦°.. μλ‘ λ¬ΌλΆμΌλ©΄ λ°μΌλ‘ λμ€κ² μ£ ? (λ¨Όμ λ€μ΄κ°κ±΄ λ¨Όμ λμ¨λ€!)
- μνκΈ°λ₯Ό μκ°νλ©΄ λκ²μ£ ? λ¨Όμ μ μ¬λμ΄ λ¨Όμ λκ°λ..(μ-_-μΉκΈ° μ μΈ)
- Frontλ νμ 맨 μμ κ°λ₯΄ν€λ λ³μ, Rearλ νμ 맨 λ μμλ₯Ό κ°λ₯΄ν€λ λ³μ
1.1. λ°°μ΄λ‘ ꡬνν Queue ¶
~cpp
class Queue
{
enum {Size=100};
private:
int m_nFront;
int m_nRear;
int m_nData[Size];
bool IsEmpty();
bool IsFull();
public:
Queue() {m_nFront=m_nRear=-1;}
bool Add(int ndata);
bool Erase();
void Show();
~Queue() {}
};
bool Queue::IsEmpty()
{
true;
return false;
}
bool Queue::IsFull()
{
if(m_nRear==Size-1 && m_nFront!=m_nRear)
return true;
return false;
}
bool Queue::Add(int ndata)
{
if(!IsFull())
{
m_nData[++m_nRear]=ndata;
return true;
}
else
{
cout<<"κ½μ°Όλ€";
return false;
}
}
bool Queue::Erase()
{
if(!IsEmpty())
{
m_nFront++;
return true;
}
else
{
cout<<"λΉμλ€";
return false;
}
}
void Queue::Show()
{
int count=m_nFront;
while(1)
{
cout<<m_nData[++count];
if(count==m_nRear)
break;
}
}
- κ·Έλ°λ°.. μ΄ νλ λ¬Έμ μ μ΄ μμ΅λλ€.
- μμλ₯Ό ν 90κ° λ£κ³ κ·Έ μμλ₯Ό 90κ° λ€μ§μ°λ©΄? Frontμ Rearκ° κ°κ° 89λ₯Ό κ°λ¦¬ν€κ² λκ² μ§μ? κ·ΈλΌ λ¨λ 곡κ°μ 10-_-κ°λ°μ μλ©λλ€.
- μ΄λ κ² λλ©΄ 첨μ 100κ°μ λ°°μ΄μ ν λΉν΄μ€κ²μ€μ 90κ°λ₯Ό λͺ» μ°κ² λκ² λ€μ.
- μ΄λ₯Ό 보μνκΈ° μν΄ μν νλΌλκ² μλλλλ€. λλ λ§ν¬λ 리μ€νΈλ‘ νλ₯Ό λ§λ€μ΄μ μ νμμ΄ μ°λ λ°©λ²λ μκ² μ£ .
- μκ²λ λ§λ€μ΄λ΄μΌκ² μ£ ?^^
1.2. Linked Listλ‘ λ§λ ν ¶
~cpp
class Queue
{
private:
struct Node
{
int nData;
Node* pPrev;
};
Node* m_pFront;
Node* m_pRear;
bool IsEmpty();
public:
Queue();
~Queue();
void Add(int x);
void Remove();
};
Queue::Queue()
{
m_pFront=new Node;
m_pFront->pPrev=NULL;
m_pRear=m_pFront;
}
void Queue::Add(int x)
{
Node* temp=new Node;
temp->nData=x;
temp->pPrev=m_pRear;
m_pRear=temp;
}
void Queue::Remove()
{
if(!IsEmpty())
{
Node* temp=m_pRear->pPrev;
delete m_pRear;
m_pRear=temp;
}
else
cout<<"...";
}
bool Queue::IsEmpty()
{
if(m_pRear==m_pFront)
return true;
else
return false;
}
Queue::~Queue()
{
while(!IsEmpty())
{
Remove();
}
delete m_pFront;
}










