コード例 #1
0
ファイル: Stack.hpp プロジェクト: ethanaward/268-Lab4
T Stack<T>::pop() throw(PreconditionViolationException) {

Node<T>* temp = m_front;
T tempValue = T();

if(isEmpty()) {
	throw PreconditionViolationException("Pop attempted on an empty stack");
}

else if(size() == 1) {
	tempValue = m_front->getValue();	
	delete m_front;
	m_front = nullptr;
	m_size--;
	return(tempValue);
}

else {
	tempValue = m_front->getValue();	
	m_front = m_front->getNext();
	delete temp;
	m_size--;
	return(tempValue);
}

}
コード例 #2
0
ファイル: Stack.hpp プロジェクト: hamzasclone2/EECS-268
T Stack<T>::peek() const throw(PreconditionViolationException){
    if(isEmpty()){
        throw (PreconditionViolationException("Peek attempted on an empty stack"));
    }
    else{
        return m_front->getValue();
    }
}
コード例 #3
0
ファイル: Stack.hpp プロジェクト: hamzasclone2/EECS-268
void Stack<T>::pop() throw(PreconditionViolationException){
    if(isEmpty()){
        throw (PreconditionViolationException("Pop attempted on an empty stack"));
    }
    else{
        m_front->getValue();
        m_front=m_front->getNext();
        m_size--;
    }
}
コード例 #4
0
ファイル: Stack.hpp プロジェクト: jancpp/Classwork-Resume
T Stack<T>::peek() const throw(PreconditionViolationException){

	if(isEmpty()){
		throw(PreconditionViolationException("Exception: Peek attempted on an empty stack\n"));
	}

	else{
		return (m_top->getValue());
	}
}
コード例 #5
0
ファイル: Stack.hpp プロジェクト: dravidjoseph/School
T Stack<T>::peek() const throw(PreconditionViolationException){
	
	//throw exception if list is empty
	if(isEmpty()){
		throw PreconditionViolationException("Peek attempted on empty stack.\n");
	}
	//return top value of the stack
	else{
		return m_top->getValue();
	}
}
コード例 #6
0
ファイル: Stack.hpp プロジェクト: jancpp/Classwork-Resume
T Stack<T>::pop() throw(PreconditionViolationException){
	
	if(isEmpty()){
		throw(PreconditionViolationException("Exception: Pop attempted on an empty stack\n"));
	}
	else{

		Node<T>* n = (m_top->getNext());
		T temp = (m_top->getValue());
		delete m_top;
		m_size--;
		m_top = n;
		return temp;
	}
}
コード例 #7
0
ファイル: Stack.hpp プロジェクト: sharynneazhar/coursework
void Stack<T>::pop() throw(PreconditionViolationException)
{
    if (isEmpty())
    {
        throw PreconditionViolationException("Pop attempted on an empty stack");
    }
    else
    {
        Node<T>* nodeToDelete = m_top;
        m_top = m_top->getNext();
        m_size--;

        delete nodeToDelete;
        nodeToDelete = nullptr;
    }
}
コード例 #8
0
ファイル: Stack.hpp プロジェクト: dravidjoseph/School
void Stack<T>::pop() throw(PreconditionViolationException){
	//throws exception if list is empty
	if(isEmpty()){
		throw PreconditionViolationException("Pop attempted on empty stack.\n");
	}
	
	else{
		//temporary pointer that moves
		Node<T>* traverse = m_top;
		
		//move m_top pointer so traverse is the only pointer holding node to be deleted
		m_top = m_top->getNext();
		
		//delete node and set traverse to nullptr
		delete traverse;
		traverse = nullptr;
		
		//decrement to reflect that one fewer node exists
		m_size--;
	}
}