void DLL::push_after(int val,int after){ LI::iterator it=find(after); if(it!=dt.end()){ ++it; dt.insert(it,val); } }
/** * @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; }
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(); } }
void DLL::del(int val){ LI::iterator it=find(val); if(it!=dt.end()) dt.erase(it); }
LI::iterator DLL::find(int val){ LI::iterator it; for(it=dt.begin();it!=dt.end();++it) if((*it) == val) return it; return it; }
void DLL::print(){ LI::iterator it; for(it=dt.begin();it!=dt.end();++it) cout << (*it) << "->"; cout << "NULL" << endl; }