(2011.07.20) 체인스택//Link list-based stack implementation
//
// Link list-based stack implementation
template <class Elem>
class LStack: public Stack<Elem>
{
private:
Link<Elem>* top; // Pointer to first element
int size; // Count number of elements
public:
LStack(int sz = DefaultListSize) { top = NULL; size = 0;}
~LStack() { clear();} // Destructor
void clear() // Delete link nodes
{
while(top != NULL)
{
Link<Elem>* temp = top;
top = top -> next;
size = 0;
delete temp;
}
}
bool push (const Elem& item)
{
top = new Link<Elem>(item, top);
size++;
return true;
}
bool pop(Elem& it)
{
if (size == 0) return false;
it = top -> element;
Link<Elem>* ltemp = top -> next;
delete top;
top = ltemp;
size--;
return true;
}
bool topValue(Elem& it)const
{
if(size == 0) return false;
it = top -> element;
return true;
}
int length() const { return size; }
};
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
언제가 아닌가프로그래밍 언어에서 null 참조가 수십억 달러의 실수라는 말을 이미 들었을 것입니다. Java의 유명하고 두려운 NullPointerException은 여러분이 알고 있거나 C의 분할 오류일 수 있습니다. 모든 상...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.