Пример #1
0
	FunctionDesignator::FunctionDesignator(std::pair< int, int > beginP,AbstractNode* ident_,std::vector<AbstractNode*>* actualParametrList_,std::pair< int, int > endP):AbstractNode(beginP,endP){
		ident = ident_;
		reverseVector(actualParametrList_);
		actualParametrList=actualParametrList_;
		beginPos = beginP;
		endPos = endP;
	}
    vector<vector<int>> zigzagLevelOrder(TreeNode* root) {
    	vector<vector<int>> res;
    	vector<TreeNode*> v;

    	if(root != NULL)
    		v.push_back(root);

    	while(!v.empty()){
    		vector<TreeNode*> temp;
    		vector<int> sibling;
    		for(int i = 0; i < v.size(); i++){
    			sibling.push_back(v[i]->val);
    			if(v[i]->left != NULL)
    				temp.push_back(v[i]->left);
    			if(v[i]->right != NULL)
    				temp.push_back(v[i]->right);
    		}
    		v = temp;
    	}  

    	for(int i = 2; i < res.size(); i += 2){
    		reverseVector(res[i]);
    	}

    	return res; 
    }
Пример #3
0
	CollectionType::CollectionType(std::pair< int, int > beginP,AbstractNode* collectionName_, std::vector<AbstractNode*>* identifierList_, std::pair< int, int > endP) : AbstractNode(beginP,endP){
		collectionName=collectionName_;
		reverseVector(identifierList_);
		identifierList = identifierList_;
		beginPos = beginP;
		endPos = endP;
	}
Пример #4
0
	FunctionDeclaration::FunctionDeclaration(std::pair< int, int > beginP,AbstractNode* functionName_,std::vector<AbstractNode*>* formalParametrList_,AbstractNode* typeIdent_,AbstractNode* block_,std::pair< int, int > endP) : AbstractNode(beginP,endP){
		functionName =functionName_;
		typeIdent = typeIdent_;
		reverseVector(formalParametrList_);
		formalParametrList = formalParametrList_;
		block = block_;
		beginPos = beginP;
		endPos = endP;
	}
void traverse_uniq_element(vector<vector<int>>& res, vector<int>& sortedCandidates, vector<int> candidateSum, int extra, int index, vector<int> subRes)
{
	if (index < 0)
		return;
	if (extra == 0)
	{
		res.push_back(reverseVector(subRes));
		/*if (!subRes.empty())
		{
			extra = subRes.back();
			vector<int>::iterator endIterator = subRes.end();
			subRes.erase(--endIterator);
			traverse_uniq_element(res, sortedCandidates, candidateSum, extra, index - 1, subRes);

		}*/
		return;
	}
	if (extra > candidateSum[index])
		return;
	if (index == 0)
	{
		if (extra == sortedCandidates[index])
		{
			subRes.push_back(extra);
			res.push_back(reverseVector(subRes));
		}
		return;
	}
	int currentData = sortedCandidates[index];
	int diffIndex = index;
	while (diffIndex >= 0 && sortedCandidates[diffIndex] == currentData)
		diffIndex--;
	traverse_uniq_element(res, sortedCandidates, candidateSum, extra, diffIndex, subRes);//不添加当前元素
	if (extra >= sortedCandidates[index])
	{
		subRes.push_back(sortedCandidates[index]);
		traverse_uniq_element(res, sortedCandidates, candidateSum, extra - sortedCandidates[index], index - 1, subRes);
	}

}
 vector<vector<int> > Print(TreeNode* pRoot) {
     vector<vector<int> > layer;
     if (!pRoot)
         return layer;
     TreeNode* current;
     queue<TreeNode*> queue1,queue2;
     queue<TreeNode*> *q1 = &queue1, *q2 = &queue2;
     q1->push(pRoot);
     vector<int> sub;
     sub.push_back(pRoot->val);
     layer.push_back(sub);
     bool reverse = true;
     while (!q1->empty()) {
         current = q1->front();
         q1->pop();
         if (current->left)
             q2->push(current->left);
         if (current->right)
             q2->push(current->right);
         if (q1->empty()) {
             vector<int> sublayer;
             while (!q2->empty()) {
                 q1->push(q2->front());
                 sublayer.push_back(q2->front()->val);
                 q2->pop();
             }
             if (sublayer.size()) {
                 if (reverse) {
                     reverseVector(sublayer);
                     reverse = false;
                 }
                 else {
                     reverse = true;
                 }
                 layer.push_back(sublayer);
             }
         }
     }
     return layer;
 }