/* Сортировка кучей */ void SRT_sort_heap(void* array, int elem_size, int array_len, compare_function cf, int ascending) { void* buffer = malloc(elem_size); //_reverse(array, elem_size, array_len); int i; // Кучифицируем for (i = array_len / 2 - 1; i >= 0; --i) { _heap_heapify(array, elem_size, array_len, cf, i, buffer); } // Сохраним длинну массива в не нужной более i i = array_len; // Сортируем while (array_len > 1) { --array_len; _swap_elems(_ITH(0), _ITH(array_len), elem_size, buffer); _heap_heapify(array, elem_size, array_len, cf, 0, buffer); } if (!ascending) _reverse(array, elem_size, i, buffer); free(buffer); }
bool MgArc::_setHandlePoint(int index, const Point2d& pt, float) { if (index == 1) { return setStartMidEnd(pt, getMidPoint(), getEndPoint()); } if (index == 2) { return setStartMidEnd(getStartPoint(), getMidPoint(), pt); } if (index == 3) { return setStartMidEnd(getStartPoint(), pt, getEndPoint()); } if (index == 4) { float a = (pt - getCenter()).angle2(); return setCenterRadius(getCenter(), getRadius(), a, getEndAngle() - a); } if (index == 5) { float a = (pt - getCenter()).angle2(); return setCenterRadius(getCenter(), getRadius(), getStartAngle(), a - getStartAngle()); } if (index == 6) { return setTanStartEnd(pt - getStartPoint(), getStartPoint(), getEndPoint()); } if (index == 7) { return (setTanStartEnd(getEndPoint() - pt, getEndPoint(), getStartPoint()) && _reverse()); } return setCenterStartEnd(pt, getStartPoint(), getEndPoint()); }
static char *_bamqual(const bam1_t * bam, BAM_DATA bd) { const uint32_t len = bam->core.l_qseq; const unsigned char *bamq = bam1_qual(bam); char *s = Calloc(len + 1, char); for (uint32_t i = 0; i < len; ++i) s[i] = bamq[i] + 33; if (bd->reverseComplement && (bam1_strand(bam) == 1)) _reverse(s, len); s[len] = '\0'; return s; }
Node *_reverse(Node *input, Node *output){ Node *temp; if (input==NULL) { return output; } temp=input->next; input->next=output; return _reverse(temp,input); }
int main() { char current_line[MAX_LINE] = { '\0' }; uint32_t length = 0; while (_getline(current_line, &length) > 0) { char reversed_line[MAX_LINE] = { '\0' }; _reverse(current_line, reversed_line); printf("%s\n", reversed_line); } return 0; }
void _merge_without_extra_space(int* nums, int left, int mid, int right) { int p = left; while (p <= mid && mid < right) { while (p <= mid && nums[p] <= nums[mid+1]) { p++; } if (p > mid) { break; } int offset = 1; while (mid + offset + 1 <= right && nums[p] > nums[mid + offset + 1]) { offset++; } // offset -= 1; _reverse(nums, p, mid + offset); _reverse(nums, p, p + offset - 1); _reverse(nums, p + offset, mid+offset); p += offset; mid = mid + offset; } }
bool MgArc::_setHandlePoint2(int index, const Point2d& pt, float, int& data) { static float lastSweepAngle; if (index == 1 || index == 2) { // 起点、终点 return setCenterRadius(getCenter(), pt.distanceTo(getCenter()), getStartAngle(), getSweepAngle()); } if (index == 3) { // 弧线中点 return setStartMidEnd(getStartPoint(), pt, getEndPoint()); } if (index == 4) { // 改变起始角度 if (data == 0) { lastSweepAngle = getSweepAngle(); data++; } Point2d startPt(getCenter().polarPoint((pt - getCenter()).angle2(), getRadius())); bool ret = setCSE(getCenter(), startPt, getEndPoint(), lastSweepAngle); lastSweepAngle = getSweepAngle(); return ret; } if (index == 5) { // 改变终止角度 if (data == 0) { lastSweepAngle = getSweepAngle(); data++; } Point2d endPt(getCenter().polarPoint((pt - getCenter()).angle2(), getRadius())); bool ret = setCSE(getCenter(), getStartPoint(), endPt, lastSweepAngle); lastSweepAngle = getSweepAngle(); return ret; } if (index == 6) { return setTanStartEnd(pt - getStartPoint(), getStartPoint(), getEndPoint()); } if (index == 7) { return (setTanStartEnd(getEndPoint() - pt, getEndPoint(), getStartPoint()) && _reverse()); } return offset(pt - getCenter(), -1); }
Node *reverse(Node *in) { return _reverse(in,NULL); }
QVariant ZStringFormatter::transform(QVariant val){ if(method() == ZFMT_METHOD_STR_CONCAT){ //! concat( with ) return _concat(val,arg("with",ZML_DEFAULT_PARAM_NAME)); }else if(method() == ZFMT_METHOD_STR_DOWNCASE){ //! downcase return _downcase(val); }else if(method() == ZFMT_METHOD_STR_ELIDE){ //! elide( [maxLength [, placeholder]] ) if(arg("placeholder").isValid()) return _elide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt(), arg("placeholder").toString()); else return _elide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt()); }else if(method() == ZFMT_METHOD_STR_LEFT){ //! left( length ) return _left(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt()); }else if(method() == ZFMT_METHOD_STR_LEFTOF){ //! leftOf( delimiter ) return _leftOf(val, arg("delimiter",ZML_DEFAULT_PARAM_NAME).toString()); }else if(method() == ZFMT_METHOD_STR_LELIDE){ //! lelide( [maxLength [, placeholder]] ) if(arg("placeholder").isValid()) return _lelide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt(), arg("placeholder").toString()); else return _lelide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt()); }else if(method() == ZFMT_METHOD_STR_LPAD){ //! lpad( length [, symbol] ) if(arg("symbol").isValid()) return _lpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt(), arg("symbol").toChar()); else return _lpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt()); }else if(method() == ZFMT_METHOD_STR_LSHIFT){ //! lshift( places ) return _lshift(val, arg("places", ZML_DEFAULT_PARAM_NAME).toUInt()); }else if(method() == ZFMT_METHOD_STR_LTRIM){ //! ltrim( [pattern] ) if(arg("pattern").isValid()) return _ltrim(val, arg("pattern",ZML_DEFAULT_PARAM_NAME).toString()); else return _ltrim(val); }else if(method() == ZFMT_METHOD_STR_RELIDE){ //! relide( [maxLength [, placeholder]] ) if(arg("placeholder").isValid()) return _relide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt(), arg("placeholder").toString()); else return _relide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt()); }else if(method() == ZFMT_METHOD_STR_REPEAT){ //! repeat( times ) return _repeat(val, arg("times",ZML_DEFAULT_PARAM_NAME).toUInt()); }else if(method() == ZFMT_METHOD_STR_REVERSE){ //! reverse return _reverse(val); }else if(method() == ZFMT_METHOD_STR_RIGHT){ //! right( length ) return _right(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt()); }else if(method() == ZFMT_METHOD_STR_RIGHTOF){ //! rightOf( delimiter ) return _rightOf(val, arg("delimiter",ZML_DEFAULT_PARAM_NAME).toString()); }else if(method() == ZFMT_METHOD_STR_RPAD){ //! rpad( length [, symbol] ) if(arg("symbol").isValid()) return _rpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt(), arg("symbol").toChar()); else return _rpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt()); }else if(method() == ZFMT_METHOD_STR_RSHIFT){ //! rshift( places ) return _rshift(val, arg("places",ZML_DEFAULT_PARAM_NAME).toUInt()); }else if(method() == ZFMT_METHOD_STR_RTRIM){ //! rtrim( [pattern] ) if(arg("pattern").isValid()) return _rtrim(val, arg("pattern",ZML_DEFAULT_PARAM_NAME).toString()); else return _rtrim(val); }else if(method() == ZFMT_METHOD_STR_SCASE){ //! capitalize return _sentenceCase(val); }else if(method() == ZFMT_METHOD_STR_SQUEEZE){ //! squeeze( [symbol] ) if(arg("symbol").isValid()) return _squeeze(val, arg("symbol",ZML_DEFAULT_PARAM_NAME).toChar()); else return _squeeze(val); }else if(method() == ZFMT_METHOD_STR_TCASE){ //! titleize return _titleCase(val); }else if(method() == ZFMT_METHOD_STR_TRIM){ //! trim( [pattern] ) if(arg("pattern").isValid()) return _trim(val, arg("pattern",ZML_DEFAULT_PARAM_NAME).toString()); else return _trim(val); }else if(method() == ZFMT_METHOD_STR_UPCASE){ //! upcase return _upcase(val); } return val; }