示例#1
0
int main(){
	ArrayStack s;
	try{
		if(s.isEmpty()){
			cout << "Stack is empty"<< endl;
		}
		
		s.Push(349);
		s.Push(49);
		s.Push(679);
		
		// Print size of stack
		cout << "Size of stack = " << s.Size() << endl;
		
		// Print top element in stack
		cout << "Top Element " << s.Top() << endl;
		
		// Print popped element from stack
		cout << "Element " << s.Pop() << " popped." << endl;
		
		// Print popped element from stack
		cout << "Element " << s.Pop() << " popped." << endl;
		
		// Print popped element from stack
		cout << "Element " << s.Pop() << " popped." << endl;
		
		// Print popped element from stack
		cout << "Element " << s.Pop() << " popped." << endl;
	}catch(...)
		cout << "Some exception occured." << endl;
	}
	
}
示例#2
0
void main() {

	ArrayStack myArrayStack;

	myArrayStack.isEmpty();

	myArrayStack.Push(45);
	myArrayStack.Push(4);
	myArrayStack.Push(34);
	myArrayStack.Push(99);
	myArrayStack.Push(1200);
	//myArrayStack.Push(771);		//causes stack overflow

	myArrayStack.isEmpty();
	cout << myArrayStack.Size() << endl;

	cout << "\nTop element: " << myArrayStack.Top() << endl;

	cout << "\nRemoving top element: " << myArrayStack.Pop() << endl;

	cout << "\nCurrent top element: " << myArrayStack.Top() << endl;

	cout << myArrayStack.Size() << endl;


	getchar();

}
示例#3
0
void Rationalizer::RewriteNodeAsCall(GenTree**             use,
                                     ArrayStack<GenTree*>& parents,
                                     CORINFO_METHOD_HANDLE callHnd,
#ifdef FEATURE_READYTORUN_COMPILER
                                     CORINFO_CONST_LOOKUP entryPoint,
#endif
                                     GenTreeArgList* args)
{
    GenTree* const tree           = *use;
    GenTree* const treeFirstNode  = comp->fgGetFirstNode(tree);
    GenTree* const insertionPoint = treeFirstNode->gtPrev;

    BlockRange().Remove(treeFirstNode, tree);

    // Create the call node
    GenTreeCall* call = comp->gtNewCallNode(CT_USER_FUNC, callHnd, tree->gtType, args);

#if DEBUG
    CORINFO_SIG_INFO sig;
    comp->eeGetMethodSig(callHnd, &sig);
    assert(JITtype2varType(sig.retType) == tree->gtType);
#endif // DEBUG

    call = comp->fgMorphArgs(call);
    // Determine if this call has changed any codegen requirements.
    comp->fgCheckArgCnt();

#ifdef FEATURE_READYTORUN_COMPILER
    call->gtCall.setEntryPoint(entryPoint);
#endif

    // Replace "tree" with "call"
    if (parents.Height() > 1)
    {
        parents.Index(1)->ReplaceOperand(use, call);
    }
    else
    {
        // If there's no parent, the tree being replaced is the root of the
        // statement (and no special handling is necessary).
        *use = call;
    }

    comp->gtSetEvalOrder(call);
    BlockRange().InsertAfter(insertionPoint, LIR::Range(comp->fgSetTreeSeq(call), call));

    // Propagate flags of "call" to its parents.
    // 0 is current node, so start at 1
    for (int i = 1; i < parents.Height(); i++)
    {
        parents.Index(i)->gtFlags |= (call->gtFlags & GTF_ALL_EFFECT) | GTF_CALL;
    }

    // Since "tree" is replaced with "call", pop "tree" node (i.e the current node)
    // and replace it with "call" on parent stack.
    assert(parents.Top() == tree);
    (void)parents.Pop();
    parents.Push(call);
}