template<typename TYPE>
struct Node
{
TYPE data;
Node<TYPE>* next;
};
template<typename TYPE>
// ์คํ์์๋ template๋ฅผ ํ๋๋ง ํด๋ ๋๋ค. ์ ๋ํฌํ ๊ฒ์ด ์๊ธฐ ๋๋ฌธ์. KEY๋ ํ์ ์์.
class Stack
{
private:
int count;
Node<TYPE>* top;
public:
//ํ์ ํจ์ 8๊ฐ ์์ฑ์,์๋ฉธ์,ํธ์ฌ.ํ
Stack();
~Stack();
bool PushStack(TYPE dataln); //๋ฐ์ดํฐ ๋ฐ์์ ๋
bool PopStack(TYPE& dataOut); //๋ฐ์ดํฐ ๊ฐ์ ์ธ๋ถ์ ์ ๋ฌ = &
bool StackTop(TYPE& dataOut);
bool emptyStack();
bool fullStack();
int StackCount();
};
template<typename TYPE>
Stack<TYPE>::Stack()
{
top = NULL;
count = 0;
} //Stack<TYPE>::Stack() ์์ฑ์
template<typename TYPE>
Stack<TYPE>::~Stack()
{
Node<TYPE>* temp;
while(top != NULL) // ๋ ธ๋ ํ๋ํ๋ ์ญ์ ํด์ผํจ!
{
temp = top;
top = top->next;
delete temp;
} //while(top != NULL)
count = 0;
} //Stack<TYPE>::~Stack()
template<typename TYPE>
bool Stack<TYPE>::PushStack(TYPE dataln)
{
bool success;
Node<TYPE>* newPtr;
newPtr = new NODE<TYPE>; // ๋ฉ๋ชจ๋ฆฌํ๋ณด
if(count == NULL)
{
success = false;
}
else
{
newPtr->data = dataln;
newPtr->next = top;
top = newPtr;
count++;
success = true;
}
return success;
}//bool Stack<TYPE>::PushStack(TYPE dataln)
template<typename TYPE>
bool Stack<TYPE>::PopStack(TYPE& dataOut)
{
bool success;
Node<TYPE>* dltPtr;
if( count == 0)
{
success = false;
}
else
{
dltPtr = top;
dataOut = top->data;
top = top->next;
count--;
success = true;
}
} //bool Stack<TYPE>::PopStack(TYPE& dataOut)
template<typename TYPE>
bool Stack<TYPE>::StackTop(TYPE& dataOut)
{
bool success;
if( count == 0)
{
success = false;
}
else
{
dataOut = top->data;
success = true;
}
} //bool Stack<TYPE>::StackTop(TYPE& dataOut)
template<typename TYPE>
int Stack<TYPE>::StackCount()
{
return count;
}//int Stack<TYPE>::StackCount()
template<typename TYPE>
bool Stack<TYPE>::fullStack()
{
bool success;
Node<TYPE>* tt;
//๋ฉ๋ชจ๋ฆฌํ๋ณดํ๊ธฐ
tt = new NODE<TYPE>;
if( tt = NULL )
{
return false;
}
else
{
delete tt; //ํ์์๋ ๋ฉ๋ชจ๋ฆฌ ์ญ์ ํ๊ธฐ
return true;
}
return success;
}//bool Stack<TYPE>::fullStack()
template<typename TYPE>
bool Stack<TYPE>::emptyStack()
{
// ์คํ์ด ๋น์ด์์ผ๋ฉด return true๋ฅผ ํ๋ค.
return (count== 0);
}
'# PRIVATE' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
WEB 11,18 (0) | 2010.11.18 |
---|---|
WEB 11์ 11์ผ (0) | 2010.11.11 |
WEB (0) | 2010.10.29 |
์ฒซ๋ฒ์งธ ๋ด์ฌํ๋ : [2010๊ณ ์ ํํจ๋๋์ถ์ ] Volunteer Staff (0) | 2010.10.29 |
์ ๋์ด ๊ทธ๋จ ์ฌ๋ฆฌํ ์คํธ (0) | 2010.10.10 |