示例#1
0
void DLL::push_after(int val,int after){
    LI::iterator it=find(after);
    if(it!=dt.end()){
        ++it;
        dt.insert(it,val);
    }
}
示例#2
0
    /**
     * @param numbers: Give an array numbersbers of n integer
     * @param target: you need to find four elements that's sum of target
     * @return: Find all unique quadruplets in the array which gives the sum of
     *          zero.
     */
    LLI fourSum(LI nums, int target) {
        sort(nums.begin(), nums.end());

        LLI res;
        LI set;

        fourSum(res, set, nums, 0, target);

        return res;
    }
示例#3
0
    void combine(LLI &results, LI &set, LI &candidates, int k, int target) {
        int sum = 0;
        for (int x : set)
            sum += x;

        if (sum == target) {
            LI sorted = set;
            sort(sorted.begin(), sorted.end());
            results.push_back(sorted);
            return;
        }

        if (target < sum)
            return;

        for (int i = k; i < candidates.size(); ++i) {
            set.push_back(candidates[i]);
            combine(results, set, candidates, i, target);
            set.pop_back();
        }
    }
示例#4
0
void DLL::del(int val){
    LI::iterator it=find(val);
    if(it!=dt.end()) dt.erase(it);
}
示例#5
0
LI::iterator DLL::find(int val){
    LI::iterator it;
    for(it=dt.begin();it!=dt.end();++it)
        if((*it) == val) return it;
    return it;
}
示例#6
0
void DLL::print(){
    LI::iterator it;
    for(it=dt.begin();it!=dt.end();++it)
        cout << (*it) << "->";
    cout << "NULL" << endl;
}