コード例 #1
0
ファイル: sort.c プロジェクト: UsuallyGO/Qlib
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);
        }
}
コード例 #2
0
ファイル: sort.c プロジェクト: UsuallyGO/Qlib
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);
        }
}
コード例 #3
0
ファイル: sort.c プロジェクト: UsuallyGO/Qlib
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);
            }
        }
}
コード例 #4
0
ファイル: SudukuCreator.cpp プロジェクト: suqin/Practice
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  
    }  
}  
コード例 #5
0
ファイル: 2908.c プロジェクト: KimSuHeon/BOJ
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);
}
コード例 #6
0
ファイル: uicurs.c プロジェクト: ABratovic/open-watcom-v2
static void swapcursor( void )
{
    _swap( UIData->cursor_type, OldCursorType );
    _swap( UIData->cursor_col, OldCursorCol );
    _swap( UIData->cursor_row, OldCursorRow );
    UIData->cursor_on = TRUE;
}
コード例 #7
0
ファイル: Serial_LCD.cpp プロジェクト: sebgiroux/MegaCluster
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();
}  
コード例 #8
0
ファイル: uicurs.c プロジェクト: Azarien/open-watcom-v2
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;
}
コード例 #9
0
ファイル: XTPDockBar.cpp プロジェクト: killbug2004/ghost2013
	void InvertRects()
	{
		for (int nPos = 0; nPos < GetSize(); nPos++)
		{
			CRect& rect = ElementAt(nPos).rcBar;
			_swap(rect.left, rect.top);
			_swap(rect.right, rect.bottom);
		}
	}
コード例 #10
0
ファイル: AzDmat.cpp プロジェクト: DeercoderCourse/NLP
/*-------------------------------------------------------------*/
void AzDvect::write(AzFile *file) 
{
  file->writeInt(num); 
  if (num > 0) {
    _swap(); 
    file->writeBytes(elm, sizeof(elm[0])*num); 
    _swap(); 
  }
}
コード例 #11
0
/*------------------------------------------------------------------*/
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; 
}
コード例 #12
0
/*------------------------------------------------------------------*/
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(); 
}
コード例 #13
0
ファイル: 10_41_04_15_C_3889.CPP プロジェクト: hrnn/olymp
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;
}
コード例 #14
0
ファイル: Mint4R2.cpp プロジェクト: MagistrAVSH/node3d
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];
		}
	}
}
コード例 #15
0
ファイル: AzIntPool.cpp プロジェクト: Anushaa/HiggsML
/*------------------------------------------------------------------*/
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; 
}
コード例 #16
0
ファイル: Screen_HX8353E.cpp プロジェクト: Gozhack/Energia
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);
}
コード例 #17
0
ファイル: scan.c プロジェクト: Akshay197/arules
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 */
コード例 #18
0
ファイル: heapsort.c プロジェクト: guilhermedelima/eda-2
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;
}
コード例 #19
0
ファイル: 哈希表.cpp プロジェクト: shihaokiss/Practice
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++;
}
コード例 #20
0
ファイル: tmp.c プロジェクト: smatov/task5-14
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);
}
コード例 #21
0
ファイル: Sort.cpp プロジェクト: JustZyx/DSA
//选择排序
void Sort::_selectSort()
{
    for (int i = _left; i <= _right; ++i) {
        int _min = _scanForMin(i, _right);
        _swap(Arr[i], Arr[_min]);
    }
}
コード例 #22
0
ファイル: tmp.c プロジェクト: smatov/task5-14
void
reverselines(char *lineptr[], int nlines)
{
	int i;
	for (i = 0; i < nlines / 2; i++)
		_swap((void **) lineptr, i, nlines - i - 1);
}
コード例 #23
0
ファイル: qsort.c プロジェクト: sukma89/mixedlab
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;
}
コード例 #24
0
 void _reorderUpwards(int nd)
 {
     while ( nd > 1 && _vecKeys[_heap[nd / 2]] > _vecKeys[_heap[nd]] )
     {
         _swap(nd / 2, nd);
         nd /= 2;
     }
 }
コード例 #25
0
/*------------------------------------------------------------------*/
void AzIntArr::initialize(AzFile *file)  
{
  num = file->readInt(); 
  initialize(num, 0); 

  file->seekReadBytes(-1, sizeof(ints[0])*num, ints); 
  _swap(); 
}
コード例 #26
0
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;
	}
}
コード例 #27
0
ファイル: qp_solver.cpp プロジェクト: KeithYue/twitter_nlp
// 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]);
}
コード例 #28
0
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.
}
コード例 #29
0
ファイル: AzDmat.cpp プロジェクト: DeercoderCourse/NLP
/*-------------------------------------------------------------*/
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(); 
}
コード例 #30
0
ファイル: image.cpp プロジェクト: Anaisabel95/GraphicsClass
void image::_assign(const image& src)
{
  // sanity check
  if(this == &src) return;

  // copy
  image temp(src);
  _swap(temp);

  // Done.
}