示例#1
0
文件: draw2D.c 项目: JDongian/EE319k
void drawRect(point topLeft, point botRight, unsigned char shade) {
	point topRight; point botLeft;
	if(topLeft.x > botRight.x){
		intSwap(&topLeft.x, &botRight.x);
	}if(topLeft.y > botRight.y){
		intSwap(&topLeft.y, &botRight.y);
	}
	topRight = makePoint(botRight.x, topLeft.y);
	botLeft = makePoint(topLeft.x, botRight.y);
	drawLine(topLeft, topRight, shade);
	drawLine(topRight, botRight, shade);
	drawLine(botLeft, botRight, shade);
	drawLine(topLeft, botLeft, shade);
}
void reverseIntArray(int a[], int n)
     /* It reverse the order of the first n elements of a */
{
  int i;

  for(i=0;i<n/2;i++){
    intSwap(&a[i],&a[n-i-1]);
  }
}
示例#3
0
int partition(int ** arrayptr, int leftIndex, int rightIndex, int pivotIndex)
{
  /* arrange this slice of the array so that left_items > pivot > right_items */
  int * array = *arrayptr;
  int counter, swapIndex, pivotValue;
 
  pivotValue = array[pivotIndex];
  intSwap (&array[rightIndex], &array[pivotIndex]);
  swapIndex = leftIndex;
  for (counter = leftIndex; counter < rightIndex; counter++) {
    if (array[counter] > pivotValue) {
      intSwap(&array[counter], &array[swapIndex]);
      swapIndex++;
    }
  }

  intSwap (&array[rightIndex], &array[swapIndex]);
  return swapIndex;
}
示例#4
0
int main()
{
    void (*foo)(int);
    /* the ampersand is actually optional */
    foo = &my_int_func;

	foo(2);

	int a = 2;
	int b = 5;
	printf("Before (a,b): (%d,%d)\n",a,b);
	intSwap(&a,&b);
	printf("After (a,b): (%d,%d)\n",a,b);
	printf("sizeof(int): %lu\n", sizeof(int));

	double doubleA = 3.14;
	double doubleB = 9.81;
	printf("Before (a,b): (%f,%f)\n",doubleA, doubleB);
	genericSwap(&doubleA, &doubleB, sizeof(double));
	printf("After (a,b): (%f,%f)\n",doubleA, doubleB);

	printf("Before (a,b): (%d,%d)\n",a,b);
	genericSwap(&a,&b, sizeof(int));
	printf("After (a,b): (%d,%d)\n",a,b);

	int srcArraySize = 5;
	int srcArr[5] = {0, 1, 2, 3, 4};
	int destArr[srcArraySize+1];
	int value = 999;
	for(int i=0; i<srcArraySize; i++) {
		if(i!=srcArraySize-1) {
			printf("%d, ", srcArr[i]);
		}
		else {
			printf("%d\n", srcArr[i]);
		}
	}
	intInsert(srcArr, destArr, &value, 2, 5);
	for(int i=0; i<srcArraySize+1; i++) {
		if(i!=srcArraySize) {
			printf("%d, ", destArr[i]);
		}
		else {
			printf("%d\n", destArr[i]);
		}
	}
    return 0;
}