示例#1
0
    int find_max(TreeNode * root, TreeNode ** point)
    {
        int ret = -999999;
        if (root == NULL)
        {
            *point = NULL;
            return ret;
        }

        TreeNode * p_left;
        TreeNode * p_right;

        int left = find_max(root->left, &p_left);
        int right = find_max(root->right, &p_right);

        if (root->val > left && root->val > right)
        {
            *point = root;
            return root->val;
        }
        else if (left > right)
        {
            *point = p_left;
            return left;
        }
        else
        {
            *point = p_right;
            return right;
        }
    }
示例#2
0
文件: main.c 项目: bcho/homework
int main()
{
    char _[] = "deadbeef";
    tree_t t = create_tree(_, strlen(_));

    inorder_traversal(t, print_node);
    sep;
    printf("%c %c %c", retrieve(find_min(t)), retrieve(find_max(t)),
                       retrieve(find('a', t)));
    sep;

    t = insert_tree('z', t);
    printf("%c %c %c", retrieve(find_min(t)), retrieve(find_max(t)),
                       retrieve(find('a', t)));
    sep;
    inorder_traversal(t, print_node);
    sep;
    
    delete_tree('z', t);
    printf("%c %c %c", retrieve(find_min(t)), retrieve(find_max(t)),
                       retrieve(find('a', t)));
    sep;
    inorder_traversal(t, print_node);

    dispose_tree(t);

    return 0;
}
bool glxx_buffer_values_are_less_than(GLXX_BUFFER_T *buffer, int offset, int count, int size, int value)
{
   int bsize = mem_get_size(buffer->pool[buffer->current_item].mh_storage);
   vcos_assert(size == 1 || size == 2);
   vcos_assert(offset >= 0 && size >= 0 && offset + size * count <= bsize);
   vcos_assert(!(offset & (size - 1)));
   
   if (buffer->size_used_for_max != (uint32_t)size) {
      void *data = mem_lock(buffer->pool[buffer->current_item].mh_storage);
      
      // Recalculate max
      buffer->max = find_max(bsize / size, size, data);
      buffer->size_used_for_max = size;
      
      mem_unlock(buffer->pool[buffer->current_item].mh_storage);
   }
   
   if (buffer->max < value)
      return true;
   else {
      void *data = mem_lock(buffer->pool[buffer->current_item].mh_storage);
      int max = find_max(count, size, (uint8_t *)data + offset);
      
      mem_unlock(buffer->pool[buffer->current_item].mh_storage);
      
      return max < value;
   }
}
示例#4
0
int find_max(tree_node *root){
	if(root == NULL) return MIN_VALUE;
	int max = root->data;
	int left = find_max(root->left);
	int right = find_max(root->right);
	if(max < left){
		max = left;
	}
	if(max < right){
		max = right;
	}
	return max;
}
示例#5
0
void drawPoly_zbuffer(void)
{
	int x0, y0, x1, y1, i, j, k, p0, p1;
	double z0, z1, color, z;
	int minx, maxx, miny, maxy;

	for(i = 0;i<no_planes;i++)
	{			
	   find_vectors(i);	  
	   color = intensity();
	   
	   for(j=0;j<4;j++)
	   {			
			p0 =planes[i][j];			p1 =planes[i][(j+1)%4]; 	
		   
		    x0 = vertex[p0][0];			x1 = vertex[p1][0];
			y0 = vertex[p0][1];			y1 = vertex[p1][1];	
			z0 = tmp_ver[p0][2];		z1 = tmp_ver[p1][2];

			drawSlopeIndpLine(x0, y0, z0, x1, y1, z1);
			drawSlopeIndpLine(x0+1, y0+1, z0+1, x1-1, y1-1, z1-1);
			drawSlopeIndpLine(x0-1, y0-1, z0-1, x1+1, y1+1, z1+1);							
	   }// end of each line

			   
	    minx = find_min(vertex[planes[i][0]][0], vertex[planes[i][1]][0], vertex[planes[i][2]][0],vertex[planes[i][3]][0]);
		maxx = find_max(vertex[planes[i][0]][0], vertex[planes[i][1]][0], vertex[planes[i][2]][0],vertex[planes[i][3]][0]);
	    miny = find_min(vertex[planes[i][0]][1], vertex[planes[i][1]][1], vertex[planes[i][2]][1],vertex[planes[i][3]][1]);
		maxy = find_max(vertex[planes[i][0]][1], vertex[planes[i][1]][1], vertex[planes[i][2]][1],vertex[planes[i][3]][1]);

		for(k=maxy;k>=miny;k--)
		{
			 for(j=minx; j<=maxx;j++)
			 {
			   if(temp[k+H][j+W].flag)
			   {		
					z = temp[k+H][j+W].z;
			   
					if (fabs(z - (double)cz) < fabs(zbuf[k+H][j+W] - (double)cz)) 
					{
						zbuf[k+H][j+W] = z;
						frame_buffer[k+H][j+W] = color;	
						color_buffer[k+H][j+W] = i;
					}				   
			   }
			   temp[k+H][j+W].flag = 0;
			 }		   
		} 

	}//end of each planes	
}
示例#6
0
/* implement the 'g' graphing command
*/
void
do_graph1(csv_t *D, int col) {
	/* fix column number to match array indexing */
	int array_col=col-1;

	row_buckets_t graph_buckets;
	int graph_values[GRAPHROWS] = {0};
	
	/* determine the min and max of the column */
	graph_buckets.min = find_min(D, array_col);
	graph_buckets.max = find_max(D, array_col);

	/* use the min and max to compute the size of the buckets */
	graph_buckets.bucket_step_size = bucket_size(graph_buckets.max, 
		                                graph_buckets.min, GRAPHROWS);


	/* fill an array of buckets, where the value of each index is the lower 
	   end of the bucket range */
	row_bucket_values(&graph_buckets);

	/* fill an array determining how many values are in each bucket */
	fill_buckets(&graph_buckets, D, array_col, graph_values);

	/* print the graph of bucket quantities per bucket value */
	print_bucket_graph(&graph_buckets, D->labs[col-1], graph_values);
}
void create(char *str, int d, char ans[])
{
	int n = strlen(str);
	int freq[256] = { 0 }; //character count
	for (int i = 0; i < n; ++i)
		++freq[str[i]];
	int used[256] = { 0 };
	for (int i = 0; i < n; ++i)
	{
		bool excep[256] = { false };
		bool done = false;
		while (!done)
		{
			int j = find_max(freq, excep);
			if (j == -1)
			{
				cout << "error!" << endl;
				return;
			}
			excep[j] = true;
			if (used[j] <= 0)
			{
				ans[i] = j;
				freq[j]--;
				used[j] = d;
				done = true;
			}
		}
		for (int i = 0; i < 256; ++i)
			used[i]--;
	}
	ans[n] = '\0';
}
示例#8
0
static psptnode
find_max_spy(sptree t)
{
	psptnode ptmp = find_max(t);
	t = spaly(ptmp);
	return t;
}
int LRU()//最近最少使用算法
{
	int qz[10],n = 0,i,flag,k;
	memset(qz,3,sizeof(qz));
	memset(q, 0, sizeof(q));
	Produce_Num();
	for(i = 0; i<N; i++)
	{
		flag = -1;
		for(k = 0; k < yk; k++)
			if(q[k] == num[i])
			{
				flag = k;
				break;
			}	
			for(k = yk-1; k >= 0; k--)
			{
				if(k != flag)
					qz[k]++;
			}
			if(flag != -1)
				qz[flag] = 0;
			else
			{
				k = find_max(qz);
				q[k] = num[i];
				qz[k] = 0;
				strcpy(tmp[n++]+1, q);
			}
		
			
	}
	print(n);
	return 1;
}
示例#10
0
文件: 1003.c 项目: hawkroy/algorithm
int main(int argc, char** argv) {
        int n, headcnt, i, cnt;
        RESULT ret;
#ifdef NO_ONLINE
	int dbg_i;
#endif
        
        cnt = 1;
        scanf("%d", &n);
        while (n-->0) {
        	scanf("%d", &headcnt);
        	//memset(array, 0, MAXLEN);
        	i = 0;
        	while (i < headcnt) {
        		scanf("%d", &array[i++]);
        	}
#ifdef NO_ONLINE
        	for (dbg_i = 0; dbg_i < headcnt; ++dbg_i) {
        		printf("%d ", array[dbg_i]);
        	}
        	printf("\n");
#endif
        	ret = find_max(headcnt);
        	printf("Case %d:\n", cnt++);
        	printf("%d %d %d\n", ret.sum, ret.l, ret.h);
        	if (n)
        		printf("\n");
        }
        
        return 0;
}
示例#11
0
int main(int argc, char *argv[])
{
    tree_node_t *root = NULL;
    node_value data[TEST_DATA_NUM] = {6, 2, 8, 1, 4, 9, 10, 11};
    root = insert(7, root);

    int i = 0;
    for (; i < TEST_DATA_NUM; i++)
    {
        insert(data[i], root);
    }

    logprintf("---left root right---");
    ldr_print(root);

    tree_node_t *tmp = find_min(root);
    logprintf("%sfind_min()%s = %d", YELLOW, NORMAL, tmp->element);

    tmp = find_max(root);
    logprintf("%sfind_max()%s = %d", YELLOW, NORMAL, tmp->element);

    node_value search = 8;
    tmp = find(search, root);
    if (NULL != tmp)
    {
        logprintf("%ssearch: %d is in tree%s", MAGENTA, search, NORMAL);
    }

    return 0;
}
void main()
{
	int i,j;
	double aver[10];
	int a[11][5];
	/*********************调试用*************************
	int a[10][5]={{1,1,1,1,1},{2,2,2,2,2},
	{3,3,3,3,3},{4,4,4,4,4},{5,5,5,5,5},{6,6,6,6,6},
	{7,7,7,7,7},{8,8,8,8,8},{9,9,9,9,9},{10,10,10,10,11}};
	****************************************************/
	
	for(i=0;i<10;i++)
	{
		printf("Please input Student%d's grades.\n",i+1);
		for(j=0;j<5;j++)
			scanf("%d",&a[i][j]);
	}
	
	printf("The average grade of each student is:\n");
	for(i=0;i<10;i++)
	{
		aver[i]=aver_stu(a[i]);
		printf("Student%2d: %.2lf.\n",i+1,aver[i]);
	}
		
	printf("\nThe average grade of each course is:\n");
	for(j=0;j<5;j++)
		printf("Course%d: %.2lf.\n",j+1,aver_course(a,j));

	find_max(a);
	printf("\nStudent%d got the highest score %d in Course%d.\n",a[10][0]+1,a[a[10][0]][a[10][1]],a[10][1]+1);

	printf("\nThe variance of the average grades is %.2lf\n",var(aver));
}
示例#13
0
文件: bst.cpp 项目: calmattoso/EDA
bst_ret remove(node * cur){
  node * aux = NULL;

  if(cur == NULL)
    return bst_ErrParm;

  /* while the current node is not a leaf node */
  while( cur->lchild != NULL || cur->rchild != NULL )
  {
    /* The node has no left subtree */
    if(cur->lchild == NULL){
      aux = find_min(cur->rchild);
      swap(cur, aux);
    }
    /* The node has or doesn't have a right subtree */
    else {
      aux = find_max(cur->lchild);
      swap(cur, aux);
    }
        
    cur = aux;
  }
  
  /* Fix the the pointers of cur's parent */
  if(cur->parent->lchild == cur)
	cur->parent->lchild = NULL;
  else if(cur->parent->rchild == cur)
	cur->parent->rchild = NULL;

  free(cur->key);
  free(cur);

  return bst_Ok;
}
示例#14
0
/*
* Function: sortarray
*/
void
sortarray(double prices[], int size, double *most_exp, double *least_exp)
{
	int current;
	int index;
	double temp;
	
	*most_exp = prices[0];  /* initialise max and min values */
	*least_exp = prices[0];

	/* consider one value from the array at a time */
	for(index = 0; index <= size - 1; index++)
	{
		/* find current position of maximum value in array */
		/* only search beyond the current position being considered,
		*  ie. the index value. */

		current = find_max(prices, index, size);
		if(index != current)
		
		/* If the min value does not equal the value being considered,
		*  the switch the position with the min value */
		{
		   temp = prices[index];
		   prices[index] = prices[current];
		   prices[current] = temp;
		}
		
		if (prices[index] > *most_exp)
			*most_exp = prices[index];
		if (prices[index] < *least_exp)
			*least_exp = prices[index];
	}
} 
示例#15
0
// Counting Sort (see http://en.wikipedia.org/wiki/Counting_sort)
u_int *counting_sort(u_int *input, u_int ilen) {
    u_int max_input = find_max(input, ilen),
        *count = (u_int*)malloc((max_input+1) * sizeof(u_int)),
        *output = (u_int*)malloc(ilen * sizeof(u_int)),
        i,
        total_positioned = 0,
        c_i;

    printf("MAX VALUE IN INPUT: %u\n\n", max_input);

    // Count how many times the element at "input[i]" appears in "input"
    for (i = 0; i < ilen; ++i) {
        ++count[input[i]];
    }

    // Calculate where every value "input[i]" will positioned in the "output"
    // NOTE: count will be trasformed in a MAP of where the element "input[i]" will sit
    for (i = 0; i < max_input+1; ++i) {
        c_i = count[i];
        count[i] = total_positioned;
        total_positioned += c_i;
    }

    for (i = 0; i < ilen; ++i) {
        output[count[input[i]]] = input[i];
        ++count[input[i]]; //< 1 place taken for 'input[i]', move right by 1 location
    }

    free(count);

    return output;
}
示例#16
0
void	ft_execute(int fd)
{
	t_grid			*grid;
	t_point			point;

	grid = init_grid(fd);
	ft_set_params(grid);
	if (!g_errno)
		read_first_line(grid);
	if (!g_errno)
		ft_read(grid);
	if (!g_errno)
		test_full(grid);
	if (g_errno)
		ft_putstr("Map error\n");
	else
	{
		ft_remap(grid);
		point = find_max(grid);
		draw_square(grid, point.x, point.y, point.max);
		print_index(grid);
	}
	if (fd > 0)
		close(fd);
	free_grid(grid);
}
示例#17
0
文件: iarray.c 项目: pcercuei/dcplaya
static void sort_part(iarray_t *a, int idx, int n, iarray_cmp_f cmp,
		      void * cookie)
{
  iarray_elt_t * e;

  if (n<=0) {
    return;
  }

  if (idx < 0) {
    idx = 0;
  }  else if (idx >= a->n) {
    return;
  }
  e = a->elt + idx;

  if (n+idx > a->n) {
    n = a->n-idx;
  }
  
  for (; n>0; --n) {
    int k = find_max(e, n, cmp, cookie);
    swap(e+k, e+n-1);
  }
}
示例#18
0
static void
indexed_autostretch_hsv (gint32 image_ID)
{
  guchar *cmap;
  AutostretchData data = {0.0, 1.0, 0.0, 1.0};
  gint ncols, i;

  cmap = gimp_image_get_colormap (image_ID, &ncols);

  if (!cmap)
    {
      g_message (_("autostretch_hsv: cmap was NULL!  Quitting...\n"));
      gimp_quit ();
    }

  for (i = 0; i < ncols; i++)
    {
      find_max (&cmap[i * 3], 3, &data);
    }

  for (i = 0; i < ncols; i++)
    {
      autostretch_hsv_func (&cmap[i * 3], &cmap[i * 3], 3, &data);
    }

  gimp_image_set_colormap (image_ID, cmap, ncols);
}
示例#19
0
 void clear()
 {
   while (!empty()) {
     find_max();
     remove(root->key);
   }
 }
示例#20
0
int main()
{
	init_numbers(N, nums);
	read_numbers(nums);
	print_numbers(N, nums);
	find_max(N, nums);
	return 0;
}
示例#21
0
文件: Ex3.c 项目: marrusian/C
int main(void)
{
   int arr[] = {7, -24, -11, 9, 5, 55, -4};

   printf("The largest value stored in arr is: %d\n", find_max(arr, BEYOND(arr)));

   return 0;
}
示例#22
0
Tree *find_max(Tree *t) {
	if (t == NULL) {
		return NULL;
	} else if (t->right == NULL) {
		return t;
	} else {
		return find_max(t->right);
	}
}
示例#23
0
struct bst* find_max(struct bst *T)
{
       if(T==NULL)return T;
       else
       {
           if(T->right!=NULL)return find_max(T->right);
           else return T;
       }
}
示例#24
0
tree *find_max(tree *node)
{
	if( node == NULL)
		return NULL;
	if( node->rightchild)
		return find_max(node->rightchild);
	else
		return node;
}
示例#25
0
/*
 * find the max element of the tree's chidren.
 */
BStree *find_max(BStree *tree)
{
	if(tree == NULL)
		return NULL;
	if(tree->right != NULL)
		return find_max(tree->right);
	else
		return tree;
}
示例#26
0
int mainPopulate()
{
    getLineInfo();
    char bigrams[WIDTH*HEIGHT-1][2];
    populate_bigrams(bigrams);
    int bigram_frequency_table[92][92];//only a-z considered
    populate_bigrams_freq_table(bigram_frequency_table, bigrams);
    find_max (bigram_frequency_table);
    return 0;
}
示例#27
0
文件: pmf.c 项目: ilyak/wham
static double log_sum(const double *v, int n)
{
	double max, sum = 0.0;
	int i;

	max = find_max(v, n);
	for (i = 0; i < n; i++, v++)
		sum += exp(*v - max);
	return log(sum) + max;
}
示例#28
0
int main()
{
    int ara[] = {-100, 0, 53, 22, 83, 23, 89, -132, 201, 3 , 85};
    int n = 11;
    int max = find_max(ara, n);

    printf("%d\n", max);

    return 0;
}
示例#29
0
my_bs_tree_node *
find_max(my_bs_tree t) {
    if (t == NULL) {
        return NULL;
    } else if (t->right != NULL) {
        t = find_max(t->right);
    }
    
    return t;
}
示例#30
0
float* irelief(char* matrix, char* label, int& t,int s,int f)
{
	samplecount = s;
	featurecount = f;
	msize = max(s, f);
	float* w_old = new float[featurecount];
	for (int  i = 0; i < featurecount; ++i)
	{
		w_old[i] = float(1.0)/featurecount;
	}
	float n_norm = norm_2(w_old);
	for (int i = 0; i < featurecount; ++i)
	{
		w_old[i] /= n_norm;
	}
	
	char** miss = new char*[msize];
	char** hit = new char*[msize];
	for (int i = 0; i < msize; ++i)
	{
		miss[i] = new char[msize];
		hit[i] = new char[msize];
	}
	cal(label, miss, hit);
	float theta = float(0.001);
	float* w;
	while (true)
	{
		w = compute_weight(matrix, w_old, miss, hit);
		float* temp = new float[featurecount];
		sub(w, w_old, temp);
		float stp = norm_2(temp);
		cout << "stp is "<< stp << endl;
		cout << find_max(w) << endl;
		if (stp < theta || t == 20)
			break;
		//free(w_old);
		w_old = w;
		++t;
		cout << t << endl;
	}

	for (int i = 0; i < samplecount; ++i)
	{
		delete[] hit[i];
		delete[] miss[i];
	}


	//free(miss);
	//free(hit);
	//free(w_old);

	return w;
}