void permute(char *stringPointer, int start, int end) {
  int i;
  if (start == end){
    permNumber++;
    // printf("Permutation (%d): ",permNumber);
    printf("%s\n",stringPointer);
  } else {
    for (i = start; i <= end; i++) {
      swapValues((stringPointer+start), (stringPointer+i));
      permute(stringPointer, start+1, end);
      swapValues((stringPointer+start), (stringPointer+i));
    }
  }
}
/* Utility to actually draw the line for an intron. Clips it if necessary, maintaining the same
 * angle for the line */
static void drawIntronLine(DrawData *data, const gint x1, const gint y1, const gint x2, const gint y2, GdkRectangle *clipRect)
{
  /* Only draw anything if at least part of the line is within range. We are only ever called with
   * y values that are in range so don't bother checking them. */
  const gint xMin = data->horizontal ? clipRect->x : clipRect->y;
  const gint xMax = xMin + (data->horizontal ? clipRect->width : clipRect->height);
  
  if (x1 <= xMax && x2 >= xMin)
    {
      int xStart = x1;
      int xEnd = x2;
      int yStart = y1;
      int yEnd = y2;
      
      /* Clip the start/end x values if out of range */
      if (xStart < xMin)
        {
          const int origWidth = abs(xEnd - xStart);
        
          xStart = xMin;

          const int newWidth = abs(xEnd - xStart);
          const int newHeight = roundNearest((double)(yEnd - yStart) * (double)newWidth / (double)origWidth); /* negative if yend < ystart */
          
          yStart = yEnd - newHeight;
        }

      if (xEnd > xMax)
        {
          const int origWidth = abs(xEnd - xStart);

          xEnd = xMax;

          const int newWidth = abs(xEnd - xStart);
          const int newHeight = roundNearest((double)(yEnd - yStart) * (double)newWidth / (double)origWidth);
          
          yEnd = yStart + newHeight;
        }
      
      /* Swap x and y if we're drawing the view vertically rather than horizontally */
      if (!data->horizontal)
        {
          swapValues(&xStart, &yStart);
          swapValues(&xEnd, &yEnd);
        }
      
      gdk_draw_line(data->drawable, data->gc, xStart, yStart, xEnd, yEnd);
    }
}
Пример #3
0
int main(){
	int a = 5;
	int b = 6;
	printf("a=%d, b=%d",a,b);
	getchar();
	swapValues(a,b);
	printf("a=%d, b=%d\n",a,b);
	return 0;
}
Пример #4
0
    // Siftup() takes a node that has just been added to the heap
    // and compares it to its parent. It swaps values if necessary
    // and recurses on the parent node until reaching the root.
    void siftup(int *node) {
        // base case
        if(node == root() || size() == 0) return;

        int *parent = rootOf(node);
        if(*node < *parent) swapValues(node, parent);

        // recursion
        return siftup(parent);
    }
Пример #5
0
void sort(T a[], int numberUsed)
{
	int indexOfNextSmallest;
	for(int index = 0; index<numberUsed-1; index++)
	{
		//해당 index의 원소에서 그 원소보다 뒤에 있는 원소들 중 가장 작은 값을 찾는다.
		indexOfNextSmallest = indexOfSmallest(a, index, numberUsed);
		//찾은 가장 작은 원소와 현재 index값의 원소의 값을 서로 바꾼다.
		swapValues(a[index], a[indexOfNextSmallest]);
	}
}
Пример #6
0
    // Siftdown() finds the children of the node given, compares
    // their values and swaps them if necessary. It then recurses
    // on the swapped child since the swap could have upset the
    // heap property on lower subtrees.
    void siftDown(int *node){
        // base case
        if(isLeaf(node)) return;

        int *left = leftChildOf(node), *right = rightChildOf(node);
        int *min_child = smallest(left,right);
        if(*node > *min_child) swapValues(min_child, node);

        // recursion
        siftDown(min_child);
    }
	void Container<T>::sort()
	{
		bool control=true;
		while (control)
		{
			control=false;
			for (int j = 0; j < contSize()-1; ++j)
			{
				if (elems.at(j) > elems.at(j+1))
				{
					swapValues(elems.at(j), elems.at(j+1));
					control=true;
				}
				
			}
		}
	}