void _selectSort(QSort *sort) { int index1, index2, minOrmax; size_t size; DataCompFunc cmpf; size = sort->m_elemsize; cmpf = sort->cmpf; //each time, find the minium element, to swap with the ith element if(sort->m_order == QSORT_DESCEND)//write the code segment twice, to avoid more judgement in for statement for(index1 = sort->m_begin; index1 < sort->m_length-1; index1++) { minOrmax = index1; for(index2 = index1+1; index2 < sort->m_length; index2++) { if(cmpf(sort->m_data+index2*size, sort->m_data+minOrmax*size) > 0) minOrmax = index2; } //get the element address accord to the element size //we do this because we don't know the element type, can't use sort->m_data[index1] _swap(sort->m_data+index1*size, sort->m_data+minOrmax*size, size); } else for(index1 = sort->m_begin; index1 < sort->m_length-1; index1++) { minOrmax = index1; for(index2 = index1+1; index2 < sort->m_length; index2++) { if(cmpf(sort->m_data+index2*size, sort->m_data+minOrmax*size) < 0) minOrmax = index2; } _swap(sort->m_data+index1*size, sort->m_data+minOrmax*size, size); } }
void _heapSort(QSort *sort) { int begin, end; size_t size; DataCompFunc cmpf; void *tmp; size = sort->m_elemsize; cmpf = sort->cmpf; //Make sure the last one is the biggest or least one begin =(sort->m_length - 1)/2; end = sort->m_length - 1; if(sort->m_order == QSORT_DESCEND) for( ; begin >= 0; begin--) _heap_fixup_descend(sort->m_data, begin, end, size, cmpf); else for( ; begin >=0; begin--) _heap_fixup_ascend(sort->m_data, begin, end, size, cmpf); begin = sort->m_begin; if(sort->m_order == QSORT_DESCEND) for( ; end >= 0; end--) { _swap(sort->m_data+begin*size, sort->m_data+end*size, size); _heap_fixup_descend(sort->m_data, begin, end-1, size, cmpf); } else for( ; end >= 0; end--) { _swap(sort->m_data+begin*size, sort->m_data+end*size, size); _heap_fixup_ascend(sort->m_data, begin, end-1, size, cmpf); } }
void _bubbleSort(QSort *sort) { int index1, index2; size_t size; DataCompFunc cmpf; size = sort->m_elemsize; cmpf = sort->cmpf; if(sort->m_order == QSORT_DESCEND) for(index1 = sort->m_begin; index1 < sort->m_length; index1++) { for(index2 = sort->m_length-1; index2 > index1; index2--) { if(cmpf(sort->m_data+index2*size, sort->m_data+index1*size) > 0) _swap(sort->m_data+index2*size, sort->m_data+index1*size, size); } } else for(index1 = sort->m_begin; index1 < sort->m_length; index1++) { for(index2 = sort->m_length-1; index2 > index1; index2--) { if(cmpf(sort->m_data+index2*size, sort->m_data+index1*size) < 0) _swap(sort->m_data+index2*size, sort->m_data+index1*size, size); } } }
void initRow(short row) { int col = 0; int repeat = 0; memcpy(Sudoku[row],val,sizeof(short)*9);//复制val数组 for(int i = 0; i<MaxTime;i++) { _swap(row,rand()%9,rand()%9);//随机交换Maxtime次 } if(row == 0)//如果是第一行不做下面的判断 return ; for(int col = 0;col<9;col++) { while(!colSucceed(row,col)||!matSucceed(row,col)) { _swap(row,col,col+(rand()%(9-col))); repeat++;//重复次数自增 if(repeat>MaxTime)//防止死锁 { _swap(row,col,rand()%9); col = -1; break; } } repeat=0;//repeat set 0 } }
main(){ char a[4],b[4],c; scanf("%s %s",a,b); _swap(a[0],a[2],c); _swap(b[0],b[2],c); printf("%s",atoi(a)>atoi(b)?a:b); }
static void swapcursor( void ) { _swap( UIData->cursor_type, OldCursorType ); _swap( UIData->cursor_col, OldCursorCol ); _swap( UIData->cursor_row, OldCursorRow ); UIData->cursor_on = TRUE; }
uint8_t Serial_LCD::triangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t colour) { bool b=true; // Graham Scan + Andrew's Monotone Chain Algorithm // 1. Sort by ascending x while (b) { // required x2 < x1 : x3 > x2 : y2 > y1 : y3 > y1 b=false; if (!b && (x1>x2)) { _swap(x1, x2); _swap(y1, y2); b=true; } if (!b && (x2>x3)) { _swap(x3, x2); _swap(y3, y2); b=true; } } // Graham Scan + Andrew's Monotone Chain Algorithm // 2. Sort by ascending y while (b) { // required x2 < x1 : x3 > x2 : y2 > y1 : y3 > y1 if (!b && (y1>y2)) { _swap(x1, x2); _swap(y1, y2); b=true; } if (!b && (y3>y2)) { _swap(x3, x2); _swap(y3, y2); b=true; } } // Graham Scan + Andrew's Monotone Chain Algorithm // 3. check counter-clockwise, clockwise, collinear long l= (x2 - x1)*(y3 - y1) - (y2 - y1)*(x3 - x1); if (l==0) return line(x1, y1, x3, y3, colour); if (l>0) { _swap(x1, x2); _swap(y1, y2); } l= (x2 - x1)*(y3 - y1) - (y2 - y1)*(x3 - x1); _port->print('G'); _port->print(x1); _port->print(y1); _port->print(x2); _port->print(y2); _port->print(x3); _port->print(y3); _port->print(colour); return nacAck(); }
static void swapcursor( void ) /****************************/ { _swap( UIData->cursor_type, OldCursorType ); _swap( UIData->cursor_col, OldCursorCol ); _swap( UIData->cursor_row, OldCursorRow ); _swap( UIData->cursor_attr, OldCursorAttr ); UIData->cursor_on = true; }
void InvertRects() { for (int nPos = 0; nPos < GetSize(); nPos++) { CRect& rect = ElementAt(nPos).rcBar; _swap(rect.left, rect.top); _swap(rect.right, rect.bottom); } }
/*-------------------------------------------------------------*/ void AzDvect::write(AzFile *file) { file->writeInt(num); if (num > 0) { _swap(); file->writeBytes(elm, sizeof(elm[0])*num); _swap(); } }
/*------------------------------------------------------------------*/ int AzIntArr::write(AzFile *file) { int io_len_total = file->writeInt(num); _swap(); file->writeBytes(ints, sizeof(ints[0])*num); _swap(); return io_len_total; }
/*------------------------------------------------------------------*/ void AzIntPool::write(AzFile *file) { file->writeInt(ent_num); file->writeInt8(data_num); file->writeBool(isCommitted); _swap(); file->writeBytes(data, sizeof(data[0])*data_num); file->writeBytes(ent, sizeof(ent[0])*ent_num); _swap(); }
int main () { ways = _tmp[0]; nways = _tmp[1]; freopen ("restore.in", "rt", stdin); freopen ("restore.out", "wt", stdout); scanf ("%d %d %d", &n, &m, &p); memset (ve, 0, sizeof ve); for (int i = 0; i < m; i++) { int a, b; scanf ("%d %d", &a, &b); add_edge (a - 1, b - 1); } scanf ("%d %d", &S, &t); S--; for (int i = 0; i < t; i++) scanf ("%d %d", &A[i], &B[i]); _bfs::bfs (S); for (int i = 0; i < n; i++) if (bi[i] == A[0]) nways[i] = 1; else nways[i] = 0; _swap (); B[0]--; int cur = (B[0] ? 0 : 1); while (cur < t) { for (int i = 0; i < B[cur]; i++) { for (int j = 0; j < n; j++) if (ways[j]) for (edge* e = ve[j]; e; e = e->next) if (bi[e->b] == A[cur]) nways[e->b] = (nways [e->b] + ways[j]) % p; _swap (); } cur++; } __int64 sum = 0; for (int i = 0; i < n; i++) sum = (sum + ways[i]) % p; printf ("%I64d", sum); return 0; }
void MBitmapR2::CheckDrawMode(float* fuv) { if(m_DrawMode) { float temp[2]; if(m_DrawMode & MBM_FlipLR) {//좌우 바꾸기 _swap(fuv[0],fuv[2]); _swap(fuv[1],fuv[3]); _swap(fuv[4],fuv[6]); _swap(fuv[5],fuv[7]); } if(m_DrawMode & MBM_FlipUD) {//상하 바꾸기 _swap(fuv[0],fuv[6]); _swap(fuv[1],fuv[7]); _swap(fuv[2],fuv[4]); _swap(fuv[3],fuv[5]); } if(m_DrawMode & MBM_RotL90) { temp[0] = fuv[4];temp[1] = fuv[5]; fuv[4] = fuv[6];fuv[5] = fuv[7]; fuv[6] = fuv[0];fuv[7] = fuv[1]; fuv[0] = fuv[2];fuv[1] = fuv[3]; fuv[2] = temp[0];fuv[3] = temp[1]; } if(m_DrawMode & MBM_RotR90) { temp[0] = fuv[6];temp[1] = fuv[7]; fuv[6] = fuv[4];fuv[7] = fuv[5]; fuv[4] = fuv[2];fuv[5] = fuv[3]; fuv[2] = fuv[0];fuv[3] = fuv[1]; fuv[0] = temp[0];fuv[1] = temp[1]; } } }
/*------------------------------------------------------------------*/ int AzIntPool::write(AzFile *file) { int io_len = 0; io_len += file->writeInt(ent_num); io_len += file->writeInt(data_num); io_len += file->writeBool(isCommitted); _swap(); io_len += file->writeBytes(data, sizeof(data[0])*data_num); io_len += file->writeBytes(ent, sizeof(ent[0])*ent_num); _swap(); return io_len; }
void Screen_HX8353E::_fastFill(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t colour) { if (x1 > x2) _swap(x1, x2); if (y1 > y2) _swap(y1, y2); _setWindow(x1, y1, x2, y2); digitalWrite(_pinDataCommand, HIGH); digitalWrite(_pinChipSelect, LOW); uint8_t hi = highByte(colour); uint8_t lo = lowByte(colour); for (uint32_t t=(uint32_t)(y2-y1+1)*(x2-x1+1); t>0; t--) { SPI.transfer(hi); SPI.transfer(lo); } digitalWrite(_pinChipSelect, HIGH); }
int sc_back (SCAN *scan) { /* --- go back one token */ if (scan->back) /* a second step backwards */ return scan->token; /* is impossible, so do nothing */ scan->back = -1; /* set the step backward flag */ return _swap(scan); /* swap the token information */ } /* sc_back() */ /* and return the previous token */
int _vector_heapify(Vector *v, int heapsize, int index) { // if(!v) // return ERROR_NULL_VECTOR; // if(!v->size) // return ERROR_EMPTY_VECTOR; // if(index >= v->size) // return ERROR_INVALID_INDEX; int left, right, biggest; left = _l_son(index); right = _r_son(index); if ((left < heapsize) && (v->v[left] > v->v[index])) biggest = left; else biggest = index; if ((right < heapsize) && (v->v[right] > v->v[biggest])) biggest = right; if (biggest != index) { _swap(&v->v[biggest], &v->v[index]); _vector_heapify(v, heapsize, biggest); } return OK; }
void HashBucket<K, V, H>::Insert(K& key, V& value) { int index; if (_size == _array.size()) //À©ÈÝ { HashBucket<K, V, H> tmp; int newCapacity = _getCapacity(); Node<K, V> *_old = NULL; tmp._array.resize(newCapacity); for (int i = 0; i < _array.size(); ++i) { _old = _array[i]; while (_old) { _old = _old->_next; index = H()(_array[i]->_key) % newCapacity; _array[i]->_next = tmp._array[index]; tmp._array[index] = _array[i]; _array[i] = _old; } } _swap(tmp); } Node<K, V>* cur = new Node<K,V>(key,value); index = H()(key) % _array.size(); cur->_next = _array[index]; _array[index] = cur; _size++; }
void __qsort(void *v[], int left, int right, int(*comp)(void *, void *)) { int i, last; void _swap(void *v[], int, int); if (left >= right) return; _swap(v, left, (left + right) / 2); last = left; for (i = left + 1; i <= right; i++) if ((*comp)(v[i], v[left]) < 0) _swap(v, ++last, i); _swap(v, left, last); __qsort(v, left, last - 1, comp); __qsort(v, last + 1, right, comp); }
//选择排序 void Sort::_selectSort() { for (int i = _left; i <= _right; ++i) { int _min = _scanForMin(i, _right); _swap(Arr[i], Arr[_min]); } }
void reverselines(char *lineptr[], int nlines) { int i; for (i = 0; i < nlines / 2; i++) _swap((void **) lineptr, i, nlines - i - 1); }
static int _partition(int *arr, int left, int right, int pivot) { int storedIndex = left; int pivotValue = arr[pivot]; int i; _swap(arr+right, arr+pivot); for (i = left; i < right; i++) { if (arr[i] < pivotValue) { _swap(arr+i, arr+storedIndex); ++storedIndex; } } _swap(arr+storedIndex, arr+right); return storedIndex; }
void _reorderUpwards(int nd) { while ( nd > 1 && _vecKeys[_heap[nd / 2]] > _vecKeys[_heap[nd]] ) { _swap(nd / 2, nd); nd /= 2; } }
/*------------------------------------------------------------------*/ void AzIntArr::initialize(AzFile *file) { num = file->readInt(); initialize(num, 0); file->seekReadBytes(-1, sizeof(ints[0])*num, ints); _swap(); }
void fft(vector<float>& data, unsigned long nn, int isign) { unsigned long n,mmax,m,j,istep,i; double wtemp,wr,wpr,wpi,wi,theta; float tempr,tempi; n=nn << 1; j=1; for (i=1;i<n;i+=2) { if (j > i) { _swap(data[j],data[i]); _swap(data[j+1],data[i+1]); } m=n >> 1; while (m >= 2 && j > m) { j -= m; m >>= 1; } j += m; } mmax=2; while (n > mmax) { istep=mmax << 1; theta=isign*(6.28318530717959/mmax); wtemp=sin(0.5*theta); wpr = -2.0*wtemp*wtemp; wpi=sin(theta); wr=1.0; wi=0.0; for (m=1;m<mmax;m+=2) { for (i=m;i<=n;i+=istep) { j=i+mmax; tempr=wr*data[j]-wi*data[j+1]; tempi=wr*data[j+1]+wi*data[j]; data[j]=data[i]-tempr; data[j+1]=data[i+1]-tempi; data[i] += tempr; data[i+1] += tempi; } wr=(wtemp=wr)*wpr-wi*wpi+wr; wi=wi*wpr+wtemp*wpi+wi; } mmax=istep; } }
// swap i and j inline void QP_Solver::swap_index(const int i, const int j) { _swap (y[i], y[j]); _swap (x[i], x[j]); _swap (alpha[i], alpha[j]); _swap (status[i], status[j]); _swap (G[i], G[j]); _swap (b[i], b[j]); _swap (shrink_iter[i], shrink_iter[j]); _swap (active2index[i], active2index[j]); }
void triangleMesh::_assign(const triangleMesh& tm) { // check for trivial case: self-assignment if(&tm == this) return; // create copy & swap triangleMesh copy(tm); _swap(copy); // Done. }
/*-------------------------------------------------------------*/ void AzDvect::_read(AzFile *file) { const char *eyec = "AzDvect::_read"; if (elm != NULL || num != 0) { throw new AzException(eyec, "(elm=NULL,num=0) was expected"); } num = file->readInt(); a.alloc(&elm, num, eyec, "elm"); file->seekReadBytes(-1, sizeof(elm[0])*num, elm); _swap(); }
void image::_assign(const image& src) { // sanity check if(this == &src) return; // copy image temp(src); _swap(temp); // Done. }