コード例 #1
0
ファイル: heap-test.c プロジェクト: ruvolof/c-edu
int main () {
	IntMinHeap h;
	int n, i, val;
	
	printf("How many value would you like to add to the heap? ");
	scanf("%d", &n);
	
	h = newIntMinHeap(n);
	
	printf("Insert values:\n");
	for (i = 0; i < n; i++) {
		scanf("%d", &val);
		enqueueIntMinHeap(&h, val);
	}
	
	printf("This is your heap:\n");
	printIntArray(h.array, h.size);
	
	dequeIntMinHeap(&h, &val);
	printf("Its first value is: %d\n", val);
	
	printf("Now the heap is:\n");
	printIntArray(h.array, h.size);
	
	return 0;
}
コード例 #2
0
int main(void) {
  int x[NMAX];
  int hmny;

  hmny = getIntArray(x, NMAX, 0);
  printf("The array was: \n");
  printIntArray(x,hmny);
  reverseIntArray(x,hmny);
  printf("after reverse it is:\n");
  printIntArray(x,hmny);
}
コード例 #3
0
/* A function to print all pool information. 
 */
void printPoolInfo(BM_PoolInfo *pi) {
  SM_FileHandle *fh = pi->fh;
  printf("numPages:\t\t %d\n", pi->numPages);
  printf("fh->fileName:\t\t %s\n", fh->fileName);
  printf("fh->totalNumPages:\t\t %d\n", fh->totalNumPages);
  printBoolArray("dirtys", pi->dirtys, pi->numPages);
  printIntArray("fixCounter", pi->fixCounter, pi->numPages);
  printIntArray("map", pi->map, pi->numPages);
  printf("fifo_old:\t\t %d\n", pi->fifo_old);
  printIntArray("lru_stamp", pi->lru_stamp, pi->numPages);
  printStrArray("frames", pi->frames, pi->numPages);

}
コード例 #4
0
ファイル: SelectSort.c プロジェクト: JunStar/algorithm_in_c
int main(){
	int data[] = {8,5,3,1,9,2,7,4,6};
	int len;
	GET_ARRAY_LEN(data, len);

	// 打印原始需排序成员
	printf("original : ");
	printIntArray(data, len);

	// 冒泡排序
	SelectSort(data, len);

	// 打印最终结果
	printf("result : ");
	printIntArray(data, len);
}
コード例 #5
0
ファイル: experiments.cpp プロジェクト: ziyan/unfollow
void getSampledDistance(const PNGraph& graph, std::vector<int> srcIds, std::vector<int> dstIds, int sampleSize, TFltPrV& ret) {
	std::random_shuffle(srcIds.begin(), srcIds.end());
	std::random_shuffle(dstIds.begin(), dstIds.end());

	int distance[20];
	for (int i = 0; i < 20; distance[i++] = 0);

	int sampleCount = 0;
	for (int i = 0; i < sampleSize; ) {
		int srcNodeId = srcIds[rand() % srcIds.size()];
		int dstNodeId = dstIds[rand() % dstIds.size()];

		if (!graph->IsNode(srcNodeId)) continue;
		if (!graph->IsNode(dstNodeId)) continue;
		int shortDist = TSnap::GetShortPath(graph, srcNodeId, dstNodeId, true);
		distance[shortDist]++;
		sampleCount++;
		printIntArray(distance, 20);
		++i;
	}

	for (int i = 0; i < 20; ++i) {
		ret.Add(TFltPr(i, distance[i]));
	}
}
コード例 #6
0
/* A function to get the fix counts.
 */
int *getFixCounts (BM_BufferPool *const bm) {
  BM_PoolInfo *pi = (BM_PoolInfo *)bm->mgmtData;
  int *fc = pi->fixCounter;
  
  printIntArray("Fix count", fc, bm->numPages);

  return fc;
}
コード例 #7
0
ファイル: MergeSort.c プロジェクト: JunStar/algorithm_in_c
int main(){
	int data[] = {8,5,3,1,10,2,7,9,4,6};
	int len;
	GET_ARRAY_LEN(data, len);
	int *tmpData = (int *)malloc(sizeof(int) * len);	/* 归并排序中用到的数组,用于保存排序好之后的成员,其长度应跟data一样大小 */

	// 打印原始需排序成员
	printf("original : ");
	printIntArray(tmpData, len);

	// 快速排序
	MyMergeSort(data, tmpData, 0, len - 1);

	// 打印最终结果
	printf("result : ");
	printIntArray(tmpData, len);
}
コード例 #8
0
/* A function to get the frame contents.
 */
PageNumber *getFrameContents (BM_BufferPool *const bm) {
  BM_PoolInfo *pi = (BM_PoolInfo *)bm->mgmtData;
  PageNumber *pn = pi->map;

  printIntArray("Frames map", pn, bm->numPages);

  return pn;
}
コード例 #9
0
ファイル: merge.c プロジェクト: RedlineResearch/oicdb
int main(int argc, char **argv) {
  int x[NMAX] = {1,3,5,6,7,8,10,11,15,20,21,21,22,24,26,28,29,32,34,35}; /* The first sorted sequence */
  int y[NMAX] = {2,3,4,6,6,9,10,12,16,21,23,23,26,27,29,33,35,39,40,41}; /* The second sorted sequence */
  int z[NMAX+NMAX]; /* The merge sequence */
  int nz;

  merge(z,&nz,x,20,y,20);
  printIntArray(z,nz);
}
コード例 #10
0
ファイル: main.c プロジェクト: LumiaHuan/DataStructure
int main_BinarySearch(){
    int array[] = {0,2,3,4,5,7,8,9};
    int N = sizeof(array) / sizeof(int);
    int key = 3;
    printIntArray(array, N);
    printf("Find %d : %d\n", key, binarySearch(array, N, key));
    key = 1;
    printf("Find %d : %d\n", key, binarySearch(array, N, key));
    return 0;
}
コード例 #11
0
ファイル: red-black-tree.c プロジェクト: Mithrandir0x/so2
static void printNode(Node *current)
{
  RBData *data;

  if ( current->left != NIL )
  {
    printNode(current->left);
  }

  data = current->data;
  printf("  [%s]: { total: [%d], total_words: [%d], per_file: [ ", data->primary_key, data->total, data->total_words);
  printIntArray(data);
  printf("] }\n");

  if ( current->right != NIL )
  {
    printNode(current->right);
  }
}
コード例 #12
0
ファイル: SelectSort.c プロジェクト: JunStar/algorithm_in_c
// 选择排序
void SelectSort(int* pData, int len){
	int i,j;
	int tmp;
	int min_index;	//无序序列中最小的元素索引

	for(i = 0; i < len; i++){
		tmp = pData[i];
		for(min_index = j = i; j < len; j++){
			if(pData[min_index] > pData[j]){
				min_index = j;
			}
		}

		//将最小的值和第i个比较元素位置互换
		swapInt(&pData[i], &pData[min_index]);

		// 打印排序过程
		printf("process %d: ",i);
		printIntArray(pData, len);
	}
}
コード例 #13
0
ファイル: MergeSort.c プロジェクト: JunStar/algorithm_in_c
// 将两个有序序列数组合并成一个有序序列
void MyMergeArr(int *pA, int *pB, int start, int mid, int end) {
	int i,j,k;
	int leftIndex = start;
	int rightIndex = mid + 1;
	int m;

	// 将左右两边的数组对应项进行比较,将较小的值放入pB中
	for(i = start; leftIndex <= mid && rightIndex <= end; i++){
		if(pA[leftIndex] < pA[rightIndex]){
			pB[i] = pA[leftIndex];
			leftIndex++;
		}else{
			pB[i] = pA[rightIndex];
			rightIndex++;
		}
	}

	// 将left序列中剩余的成员接到最终序列后面
	for(j = leftIndex; j <= mid; i++, j++){
		pB[i] = pA[j];
	}

	// 将right序列中剩余的成员接到最终序列后面
	for(k = rightIndex; k <= end; i++, k++){
		pB[i] = pA[k];
	}

	/* 这一步至关重要,是将此次排序结果赋予pA,这样才能在下次排序时得到已排好序的序列 */
	for(m = start; m <= end; m++){
		pA[m] = pB[m];
	}

	// 打印排序过程
	printf("mid is %d: ", mid);
	printIntArray(pB, end - start + 1);
}
コード例 #14
0
void printArg(struct benchData* arg)
{
    switch(arg->dataType)
    {
    case kINT:
        printf("%ld\n",arg->value.intNumber);
        break;
    case kREAL:
        printf("%f\n",arg->value.real);
        break;
    case kFLOAT4:
        printf("(%f,%f,%f,%f)\n",arg->value.float4.s[0],arg->value.float4.s[1],arg->value.float4.s[2],arg->value.float4.s[3]);
        break;
    case kINT_STREAM:
        printIntArray(arg->value.intArray);
        break;
    case kREAL_STREAM:
        printRealArray(arg->value.realArray);
        break;
    case kFLOAT4_STREAM:
        printFloat4Array(arg->value.float4Array);
        break;
    }
}
コード例 #15
0
ファイル: state2steps.c プロジェクト: Judahmeek/OldCode
/*determines the number of steps a given state[] is away from the "minimal state" based on the given freq[].
The "minimal state" is the state created by step 0. Example: Freq[2,2,2,1] => Result[a,a,b,b,c,c,d].
*/
int state2steps(const short freq[], short freqSize, short state[], short stateSize){
	
	#ifdef DEBUGSTATE2STEPS
		fputs("state2steps(freq: ", stdout);
		printShortArray(freq, freqSize);
		printf(",freqSize: %d, state: ", freqSize);
		printShortArray(state, stateSize);
		printf(", stateSize: %d)\n", stateSize);
	#endif
	
	short copy[freqSize];
	short i = 0;
	for(i = 0; i < freqSize; ++i){
		copy[i] = freq[i];
	}
	--copy[0];
	
	short zeroState[stateSize];
	steps2state(freq, freqSize, zeroState, stateSize, 0);
	
	int steps = 0;
	short sigSize = stateSize - 1;
	int sig[sigSize];
	promotionSignature(copy, freqSize, sig, sigSize, 0);
	
	#ifdef DEBUGSTATE2STEPS
		fputs("After initial pSig: ", stdout);
		fputs("state2steps(copy: ", stdout);
		printShortArray(copy, freqSize);
		printf(",freqSize: %d, sig: ", freqSize);
		printIntArray(sig, sigSize);
		printf(", sigSize: %d)\n", sigSize);
	#endif
	
	for(i = 0; i < sigSize;){
		if(state[i] == zeroState[i]){
			--copy[zeroState[++i]];
		} else {
			#ifdef DEBUGSTATE2STEPS
				printTitledShortArray("state: ", state, stateSize, 1);
				printTitledShortArray("zeroState: ", zeroState, stateSize, 1);
				printf("%d != %d\n", state[i], zeroState[i]);
			#endif
			steps += sig[i];
			++copy[zeroState[i]];
    		++zeroState[i];
			while(copy[zeroState[i]] == 0){
				++zeroState[i];
			}
    		--copy[zeroState[i]];
			promotionSignature(copy, freqSize, sig, sigSize, i);
			
			#ifdef DEBUGSTATE2STEPS
				fputs("After following pSig: ", stdout);
				fputs("promotionSignature(copy: ", stdout);
				printShortArray(copy, freqSize);
				printf(",freqSize: %d, pSig: ", freqSize);
				printIntArray(sig, sigSize);
				printf(", sigSize: %d, i: %d)\n", sigSize, i);
				#ifdef ENABLEPAUSE
					systemPause();
				#endif
			#endif
			
			short k = i, l, m;
			for(l = 0; l < freqSize; ++l){
				for(m = 0; m < copy[l]; ++m){
					zeroState[++k] = l;
				}
			}
		}
	}
	
	return steps;
};
コード例 #16
0
ファイル: MP1.c プロジェクト: DEGABGED/CS-Files
int main(){
	char yn[10];
	int program_loop = 1;
	do{
		/*
			***************
			** VARIABLES **
			***************
		*/
		char high_deg[6]; //input string; holds the highest degree directly from user
		char coeffs_list[6*100]; //input string; holds the list of coefficients directly from user
		int hdnum; //holds the higest degree (int)
		int loopvar = 1; //if 0; checking loop stops;
		char * coeff_s; //string to hold each coefficient in the input string
		int coeffs_c; //counter of the while loop

		/*
			**************************
			** HIGHEST DEGREE INPUT **
			**************************
		*/
		//loop to inputcheck first input
		while(loopvar){
			high_deg[4] = '\0';
			printf("\nEnter the highest degree of the input polynomial: ");
			fgets(high_deg, 6, stdin);
			if((high_deg[4]!='\0') && (high_deg[4]!='\n')) while(getchar() != '\n');
			if(strchr(high_deg, '.') != NULL){
				printf("Error: Degree must be an integer. Try again\n");
				continue;
			}
			loopvar = isNotNumber(high_deg, &hdnum, 1);
		}

		hdnum++;
		//printf("Number is %d\n", hdnum);
		int coeffs[hdnum]; //int array of coefficients

		/*
			************************
			** COEFFICIENTS INPUT **
			************************
		*/
		loopvar = 1; //reinitializes loopvar
		//loop to inputcheck second input
		while(loopvar){
			//gets the numbers; code from http://www.tutorialspoint.com/c_standard_library/c_function_strtok.htm
			coeff_s = NULL;
			printf("\nEnter %d coefficients starting from the 0th degree.\nSeparate each input from a comma: ", hdnum);
			fgets(coeffs_list, 6*100, stdin);
			if(strchr(coeffs_list, '.') != NULL){
				printf("Error: Coefficients must be integers. Try again\n");
				continue;
			}

			//separates string into string with ',' as a delimiter
			coeff_s = strtok(coeffs_list, ",");
			coeffs_c = 0;
			while(coeffs_c < hdnum){
				if(coeff_s == NULL){
					printf("Error: incomplete coefficients. Try again\n");
					break;
				} else {
					if(isNotNumber(coeff_s, &coeffs[coeffs_c], 0)){
						break;
					}
				}
				coeff_s = strtok(NULL, ",");
				coeffs_c++;
				if(coeffs_c >= hdnum){
					//at this part, the input getting is finished and validated
					loopvar = 0;
					//checks if last coefficient is a zero
					//apparently you can help the user and consider the 0, and just change the degree
					/*
					if(coeffs[coeffs_c-1] == 0){
						printf("Error: coefficient of highest degree term can't be 0. Try again\n");
						loopvar = 1;
					}
					*/
					if(coeffs[hdnum-1] == 0){
						printf("Warning: coefficient of term of highest degree is 0. Program will change the degree of the entire polynomial.\n");
						while(coeffs[hdnum-1] == 0){
							hdnum--;
						}
					}
				}
			}
		}

		//prints out coeffs for debugging
		printIntArray(coeffs, hdnum);

		/*
			***************************
			** RATIONAL ROOT FINDING **
			***************************
		*/
		float zeroes[hdnum]; //list of zeroes
		int roots_found = 0; //index of zeroes[] to edit
		fill(zeroes, 0.0, hdnum);

		//if constant is zero
		if(coeffs[0] == 0){
			int shft; //for shifting the coefficients around
			while(coeffs[0] == 0){
				roots_found++;
				hdnum--;
				for(shft = 0; shft < hdnum; shft++){
					coeffs[shft] = coeffs[shft+1];
				}
			}
			printf("Factor: 0\n\n");
		}

		int const_coeff_fc = ((int) sqrt(fabs(coeffs[0]))) * 4; //number of maximum factors of a0. supposedly
		int const_coeff_f[const_coeff_fc]; //factors of a0
		factor(coeffs[0], const_coeff_f, const_coeff_fc);
		//printIntArray(const_coeff_f, const_coeff_fc); //for checking

		int highdeg_coeff_ff = 1;
		int c_ctr = 0;
		float x,y;
		printf("Max factors of a0: %d\n", const_coeff_fc);
		while(highdeg_coeff_ff <= fabs(coeffs[hdnum-1])){
			if(coeffs[hdnum-1]%highdeg_coeff_ff == 0){
				for(c_ctr=0; c_ctr<const_coeff_fc; c_ctr++){
					x = (float) const_coeff_f[c_ctr] / highdeg_coeff_ff;
					y = polyfxn(coeffs, hdnum, x);
					/*
					//Block of output code for debugging
					printf("***\nx:%lf:\n", x);
					printf("y:%lf:\n", y);
					printf("y times 1000000:%lf:\n", y*(1000000));
					printf("abs int y times 10-6:%lf:\n", (int) fabs(y*(1000000)));
					printf("%d / %d\n***\n\n", const_coeff_f[c_ctr], highdeg_coeff_ff);
					*/
					if((int) fabs(y*1000000) == 0){
						if(!isHere(zeroes, x, roots_found)){
							zeroes[roots_found] = x;
							if(const_coeff_f[c_ctr] % highdeg_coeff_ff != 0) printf("Factor: %d/%d\n\n", const_coeff_f[c_ctr], highdeg_coeff_ff);
							else printf("Factor: %d\n\n", (int) zeroes[roots_found]);
							roots_found++;
						}
					}
				}
			}
			highdeg_coeff_ff++;
			//printf("highdeg_coeff_ff:%d:\n", highdeg_coeff_ff);
		}

		//end of the root finding loop
		printf("\n***PRINTING ZEROES FOUND***\n");
		printFloatArray(zeroes, roots_found);

		/*
			********************
			** NEW POLYNOMIAL **
			********************
		*/
		do{
			printf("Input new polynomial? ");
			fgets(yn, 10, stdin);
			if(strcasecmp(yn, "yes\n") == 0){
				break;
			} else if(strcasecmp(yn, "no\n") == 0){
				printf("\nTerminating program.\n");
				program_loop = 0;
				break;
			} else {
				printf("Please enter only 'yes' or 'no'.\n");
			}
		}while(1);
	}while(program_loop);
}
コード例 #17
0
ファイル: printIntArrayTest.c プロジェクト: Judahmeek/OldCode
int main(){
	int x[] = {0, -1, 2};
	fputs("Test: { 0, -1, 2 } is output as ", stdout);
	printIntArray(x, 3);
	return 0;
}
コード例 #18
0
void printIntArrayPfix(char prefix[], int nums[], unsigned int size, char postfix[])
{
    printf("%s", prefix);
    printIntArray(nums, size);
    printf("%s", postfix);
}
コード例 #19
0
ファイル: group.c プロジェクト: Fuco1/yafmp
void printGroup(Group* group) {
    printIntArray(group->words);
}