void FrameCell:: addData(DataCell* dc,int b) { //m_frameData.push_back(dc); std::list<DataCell*>::iterator it=m_frameData.begin(); //std::list<DataCell*>::iterator it2=m_frameData.begin(); bool isAdded=false; for(; it!=m_frameData.end(); it++) { //it2++; if((*it)->m_sqNum==dc->m_sqNum) { isAdded=true; //printf("重复修正\n"); break; } if(isLarger((*it)->m_sqNum,dc->m_sqNum,dc->m_topsqNum)) { m_frameData.insert(it,dc); isAdded=true; if((*it)->m_sqNum<0) { //printf("error\n"); } //printf("乱序修正 %d %d %d\n",(*it)->m_sqNum,dc->m_sqNum,dc->m_timeStamp); break; } } if(!isAdded) { m_frameData.insert(m_frameData.end(),dc); } //需要添加,一帧有没有完整 iscomplete(); return; }
vector<int> maxNumber(vector<int>& nums1, vector<int>& nums2, int k) { vector<vector<int>> dp1; vector<vector<int>> dp2; getDP(nums1, dp1); getDP(nums2, dp2); reverse(dp1.begin(), dp1.end()); reverse(dp2.begin(), dp2.end()); vector<int> ans; bool isFirst = true; for (int m = 0; m <= k && m < dp1.size(); m++) { int n = k - m; if (n < 0) continue; if (n >= dp2.size()) continue; vector<int> myans = merge(dp1[m], dp2[n]); if (isFirst) { isFirst = false; ans = myans; } else { if (isLarger(myans, 0, ans, 0)) { ans = myans; } } } return ans; }
vector<int> merge(vector<int>& nums1, vector<int>& nums2) { int m = nums1.size(), n = nums2.size(); vector<int> ans(m + n, 0); int i = 0, j = 0, k = 0; while (i < m || j < n) { if (i < m && j < n) { if (isLarger(nums1, i, nums2, j)) { ans[k++] = nums1[i++]; } else { ans[k++] = nums2[j++]; } } else if (i < m) { ans[k++] = nums1[i++]; } else { ans[k++] = nums2[j++]; } } return ans; }
struct transaction * mergeSortedArrays(struct transaction *A, int ALen, struct transaction *B, int BLen) { int totLen = ALen + BLen; struct transaction *result = (struct transaction *)malloc(totLen*sizeof(struct transaction)); //struct transaction *temp = (struct transaction *)malloc(sizeof(totLen)); //struct transaction *result; if ((A == NULL) || (B == NULL)) return NULL; int i = 0, j = 0, k = 0; while ((i < ALen) && (j < BLen)) { if (isLarger(A[i].date, B[j].date) == 1) { result[k] = A[i]; i++; } else { result[k] = B[j]; j++; } k++; } while (j < BLen){ result[k] = B[j]; j++; k++; } while (i < ALen){ result[k] = A[i]; i++; k++; } return result; }