Exemplo n.º 1
0
Location CImageProcess::FindMaxLocation(vector<Location> &x, vector<Location> &y)
{
	Location v;
	v._start = FindMax(x);
	v._end = FindMax(y);
	return v;
}
Exemplo n.º 2
0
static float BestAngle (vec3_t curvel, vec3_t intentions, qbool onground)
{
	float  a1, a2;
	vec3_t cross;
	vec3_t tmp;
	float  ba;
	float  max;

	a1 = 0;
	a2 = 95;
	CrossProduct (curvel, intentions, cross);
	if (cross[2] < 0)
	{
		a1 = -a1;
		a2 = -a2;
	}

	VectorCopy(curvel, ra_curvel);
	VectorCopy(intentions, ra_intentions);

	vectoangles (curvel, tmp);
	ba = tmp[YAW];

	if (a2 > a1)
		max = FindMax (ba + a1, ba + a2, RankAngle);
	else
		max = FindMax (ba + a2, ba + a1, RankAngle);

	return max;
}
Exemplo n.º 3
0
int main()
{
    BinTree BT = NULL;
    ElementType ca[MAX] = { 4, 6, 5, 1, 8, 9, 2, 3, 7 };
    int i;
    for (i = 0; i < MAX; i++)
        BT = Insert(BT, ca[i]);

    printf("height: %d\n", GetHeight(BT));

    // test find
    assert(Find(BT, 4) == BT);
    assert(Find(BT, 5)->Data == 5);
    assert(Find(BT, 34) == NULL);

    // test min
    assert(FindMin(BT)->Data == 1);
    BT = Insert(BT, 0);
    assert(FindMin(BT)->Data == 0);

    // test max
    assert(FindMax(BT)->Data == 9);
    BT = Insert(BT, 12);
    assert(FindMax(BT)->Data == 12);

    // test delete
    Delete(BT, 1);
    assert(Delete(BT, 6) == BT);
    assert(Delete(BT, 53) == BT);
    assert(Find(BT, 1) == NULL);
    printf("pass!\n");

    return 0;
}
Exemplo n.º 4
0
main( )
{
    AvlTree T;
    Position P;
    int i;
    int j = 0;

    T = MakeEmpty( NULL );
    for( i = 0; i < 50; i++, j = ( j + 7 ) % 50 )
        T = Insert( j, T );
   /* for( i = 0; i < 50; i++ )
        if( ( P = Find( i, T ) ) == NULL || Retrieve( P ) != i )
            printf( "Error at %d\n", i );*/

  for( i = 0; i < 50; i += 2 )
        T = Delete( i, T );

    for( i = 1; i < 50; i += 2 )
        if( ( P = Find( i, T ) ) == NULL || Retrieve( P ) != i )
            printf( "Error at %d\n", i );
    for( i = 0; i < 50; i += 2 )
        if( ( P = Find( i, T ) ) != NULL )
            printf( "Error at %d\n", i );

    printf( "Min is %d, Max is %d\n", Retrieve( FindMin( T ) ),
               Retrieve( FindMax( T ) ) );
system("Pause");
    return 0;
}
Exemplo n.º 5
0
static  void    SortByRef( void )
//===============================
{
    word_list   *curr_word;
    word_list   *sort_tail;
    int         ceiling;
    int         first_word;

    sort_tail = NULL;
    ceiling = MaxRefCount + 1;
    first_word = 1;
    for(;;) {
        ceiling = FindMax( ceiling );
        if( ceiling == 0 ) break;
        curr_word = SortPtr;
        if( first_word == 1 ) {
            SortHead = SortPtr;
            curr_word = curr_word->link;
            sort_tail = SortHead;
            first_word = 0;
        }
        while( curr_word != NULL ) {
            if( curr_word->ref_count == ceiling ) {
                sort_tail->sortlink = curr_word;
                sort_tail = curr_word;
            }
            curr_word = curr_word->link;
        }
    }
}
Exemplo n.º 6
0
int main()
{	struct node* root=NULL;
	printf("How many nodes you want in tree:\n");
	int nodes,i,data;
	scanf("%d",&nodes);
	for(i=0;i<nodes;i++)
	{
		printf("Enter the value\n");
		scanf("%d",&data);
		root=Insert(root,data);
	}
	int element,found;
	printf("Enter the element you want to search\n");
	scanf("%d",&element);
	found=Search(root,element);
	if(found==0) printf("Not found\n");
	else if(found==1) printf("Found\n");
	int min=FindMin(root);
	printf("min is %d\n",min);
	int max=FindMax(root);
	printf("max is %d\n",max);
	int Height=FindHeight(root);
	printf("Heigth of tree is %d\n",Height);

}
Exemplo n.º 7
0
int main(int argc,char* argv[])
{
	Tree T;
	T = Insert(5,T);
	T = Insert(3,T);
	T = Insert(2,T);
	T = Insert(4,T);
	T = Insert(6,T);
	T = Insert(7,T);
	T = Insert(1,T);
	preorder(T);
	printf("\n");
	printf("level:%d\n",level(T));
	printf("findMaxHeight = %d\n",findMaxHeight(T));
	printf("Max = %d\n",FindMax(T));
	printf("Minimum = %d\n",FindMin(T));
	printf("PreOrder:\n");
	preOrder(T);
	printf("\n");
	printf("InOrder:\n");
	inOrder(T);
	printf("\n");
	printf("PostOrder:\n");
	postOrder(T);
	printf("\n");
	printf("find the lowest ancestor between 1 and 7:\n");
	printf("%d\n",findLowestAncestor(T,1,7));
	printf("hasSubTree:%d\n",hasSubTree(T,T));
	mirrorReverse(T);
	preOrder(T);
	printf("\n");
	return 0;
}
Exemplo n.º 8
0
int main() {
    
    
    Vector<Car> cars;
    
    Car car;
    car.name = "BMW";
    car.weight = 4500;
    car.numAirbags = 5;
    cars.add(car);
    
    car.name = "Audi";
    car.weight = 4000;
    car.numAirbags = 5;
    cars.add(car);
    
    car.name = "Benz";
    car.weight = 5000;
    car.numAirbags = 5;
    cars.add(car);
    
    Car max = FindMax(cars,SafestCar);
    
    cout << max.name << endl;
    
    
    return 0;
}
Exemplo n.º 9
0
int main( )
{

    Treap T;
    Position P;
    int i;
    int j = 0;

    T = Initialize( );
    T = MakeEmpty( NullNode );
    for( i = 0; i < NumItems; i++, j = ( j + 7 ) % NumItems )
        T = Insert( j, T );
    for( i = 0; i < NumItems; i++ )
        if( ( P = Find( i, T ) ) == NullNode || Retrieve( P ) != i )
            printf( "Error1 at %d\n", i );

    for( i = 0; i < NumItems; i += 2 )
        T = Remove( i, T );

    for( i = 1; i < NumItems; i += 2 )
        if( ( P = Find( i, T ) ) == NullNode || Retrieve( P ) != i )
           printf( "Error2 at %d\n", i );

    for( i = 0; i < NumItems; i += 2 )
        if( ( P = Find( i, T ) ) != NullNode )
            printf( "Error3 at %d\n", i );
    printf( "Min is %d, Max is %d\n", Retrieve( FindMin( T ) ),
               Retrieve( FindMax( T ) ) );

    return 0;
}
Exemplo n.º 10
0
main( )
{
    SkipList T;
    Position P;
    int i;
    int j = 0;

    T = Initialize( );
    T = MakeEmpty( T );

    for( i = 0; i < N; i++, j = ( j + 7 ) % N )
        T = Insert( j+1, T );
    printf( "Inserts are complete\n" );


    for( i = 0; i < N; i++ )
        if( ( P = Find( i, T ) ) == NULL || Retrieve( P ) != i )
            printf( "Error at %d\n", i );

    printf( "Min is %d, Max is %d\n", Retrieve( FindMin( T ) ),
               Retrieve( FindMax( T ) ) );

	//Output (  Retrieve( FindMax( T ) ) );
    return 0;
}
Exemplo n.º 11
0
int main(){
    SearchTree T;
    Position P;
    int i;
    int j = 0;

    T = MakeEmpty( NULL );
    for( i = 0; i < 50; i++, j = ( j + 7 ) % 50 )
        T = Insert( j, T );
    MiddleTraverse(T);
    for( i = 0; i < 50; i++ )
        if( ( P = Find( i, T ) ) == NULL || Retrieve( P ) != i )
            printf( "Error at %d\n", i );

    for( i = 0; i < 50; i += 2 )
        T = Delete( i, T );
    MiddleTraverse(T);
    for( i = 1; i < 50; i += 2 )
        if( ( P = Find( i, T ) ) == NULL || Retrieve( P ) != i )
            printf( "Error at %d\n", i );
    for( i = 0; i < 50; i += 2 )
        if( ( P = Find( i, T ) ) != NULL )
            printf( "Error at %d\n", i );

    printf( "Min is %d, Max is %d\n", Retrieve( FindMin( T ) ),
               Retrieve( FindMax( T ) ) );

    return 0;
}
Exemplo n.º 12
0
/*************************************************
	Function: 		SwapMaxMin
	Description: 	交换数组中最大最小值
	Calls: 			
	Called By:		main
	Input: 			无
	Output: 		无
	Return: 		0
*************************************************/
void SwapMaxMin(int num, int *array)
{
	int * Max;
	int * Min;
	Max = FindMax(num, array);
	Min = FindMin(num, array);
	swap(Max, Min);
}
Exemplo n.º 13
0
void main()
{
	// 创建二叉搜索树的根节点
	SearchTree T;
	T = Insert(20, NULL);
	
	// 一系列的插入操作
	T = Insert(15, T);
	T = Insert(16, T);
	T = Insert(25, T);
	T = Insert(21, T);
	T = Insert(27, T);
	T = Insert(5, T);
	T = Insert(2, T);

	printf("后序遍历:");
	PrintTree(T, 0);
	printf("\n");
	printf("中序遍历:");
	PrintTree(T, 1);
	printf("\n");
	printf("前序遍历:");
	PrintTree(T, 2);
	printf("\n");

	// 查看插入的节点是否正确
	Position TmpCell;
	TmpCell = FindMin(T);
	printf("最小值为 %d \n", TmpCell->Element);
	TmpCell = FindMax(T);
	printf("最大值为 %d \n", TmpCell->Element);
	TmpCell = Find(15, T);
	printf("想要查询的值为15,实际结果为%d \n", TmpCell->Element);

	// 删除原本最大值和最小值后
	T = Delete(2, T);
	T = Delete(27, T);
	TmpCell = FindMin(T);
	printf("==删除最大值和最小值后==\n最小值为 %d \n", TmpCell->Element);
	TmpCell = FindMax(T);
	printf("最大值为 %d \n", TmpCell->Element);
	TmpCell = Find(15, T);
	// 清空树,释放所有节点所占用的空间
	MakeEmpty(T);
}
Exemplo n.º 14
0
Position FindMax(SplayTree T) {
	if (T == NULL) {
		return NULL;
	}
	if (T->Right != NULL) {
		T = FindMax(T->Right);
	}
	return T;
}
Exemplo n.º 15
0
static Node NodeDelete(Node rootnode , Node delnode){
    if (delnode == NULL || rootnode == NULL){
        return NULL;
    }
    //node in the left
    if (delnode -> data < rootnode -> data){
        rootnode -> left = NodeDelete(rootnode -> left , delnode);
        //lose balance
        if (Height(rootnode -> right) == Height(rootnode -> right) + 2){
            Node right = rootnode -> right;
            if (Height(right -> left) > Height(right -> right)){
                rootnode = RL(rootnode);
            }else{
                rootnode = RR(rootnode);
            }
        }
    }
    //node in the right
    if (delnode -> data > rootnode -> data){
        rootnode -> right = NodeDelete(rootnode -> right , delnode);
        //lose balance
        if (Height(rootnode -> left) == Height(rootnode -> right) + 2){
            Node left = rootnode -> left;
            if (Height(left -> right) > Height(left -> left)){
                rootnode = LR(rootnode);
            }else{
                rootnode = LL(rootnode);
            }
        }
    }
    //delnode is rootnode
    if (delnode -> data == rootnode -> data){
        if ((rootnode -> left != NULL) && (rootnode -> right != NULL)){
            //left is lager than right
            if (Height(rootnode -> left) > Height(rootnode -> right)){
                Node max = FindMax(rootnode -> left);
                rootnode -> data = max -> data;
                rootnode -> left = NodeDelete(rootnode -> left , max);
            }else{
            //right is lager than left
                Node min = FindMin(rootnode -> right);
                rootnode -> data = min -> data;
                rootnode -> right = NodeDelete(rootnode -> right , min);
            }
        }else{
        //left || right in null
            Node tmp = rootnode;
            if (rootnode -> left != NULL){
                rootnode = rootnode -> left;
            }else{
                rootnode = rootnode -> right;
            }
            free(tmp);
        }
    }
    return rootnode;
}
Exemplo n.º 16
0
Position FindMax(SearchTree T)
{
	if (T == NULL)
		return NULL;
	if (T->Right == NULL)
		return T;
	else
		return FindMax(T->Right);
}
Exemplo n.º 17
0
int main(void)
{
    const int input[] = {0, 0, 4, 0, 0, 6, 0, 0, 3, 0, 5, 0, 1, 0, 0, 0};
    const int input_len = sizeof(input)/sizeof(int);

    const int expected_output = 26;

    int max_idx = FindMax(input, 0, input_len); 
    printf("max_idx = %d\n", max_idx);

    for(int i=0; i<input_len; i++)
        printf("%3d,", input[i]);
    printf("\n");
    for(int i=0; i<input_len; i++)
        printf("%3d,",i);
    printf("\n");

    int pool_size = 0;

    int left_max_idx = max_idx;
    while(1)
    {
        int left_max_2nd_idx = FindMax(input, 0, left_max_idx-1);
        if(left_max_2nd_idx==0 || left_max_2nd_idx==-1)
            break;
        pool_size += CalculatePoolSize(input, left_max_2nd_idx, left_max_idx);
        left_max_idx = left_max_2nd_idx;
    }

    int right_max_idx = max_idx;
    while(1)
    {
        int right_max_2nd_idx = FindMax(input, right_max_idx+1, input_len-1);
        if(right_max_2nd_idx==input_len-1 || right_max_2nd_idx==-1)
            break;
        pool_size += CalculatePoolSize(input, right_max_idx, right_max_2nd_idx);
        right_max_idx = right_max_2nd_idx;
    }

    printf("Answer is %d\n", pool_size);

    return 0;
}
Exemplo n.º 18
0
int main()
{
    char s[1000];
    int a[256],n, c1, c2, r, count=0;// n is number of deletions that can be done; c1, c2 is the max, min frequency value respectively. 
    cin>>s;
    cin>>n;
    for(int i=0;i<256;i++)
    a[i]=0;

    for(int i=0;s[i]!=NULL;i++)
    {
            if(a[s[i]]==0)
            count++;// count will keep the track of number of different character in the string at any time
            a[s[i]]+=1;
    }
    
    c1=FindMax(a);
    c2=FindMin(a);
    r=c1-c2;
    while(n>0 && c1>0 && c2>0)
    {
        if(n<r && count>2 && ((c1-a[ssi])<=(r-n)) && (c2<=n))
        {
         n-=c2;
         a[minindex]=0;
         c1=FindMax(a);
         c2=FindMin(a); 
        }
        else 
        {
            a[maxindex]-=1;
            c1=FindMax(a);
            c2=FindMin(a); 
            n--;
        }
    }
        
               
     cout<<"\n"<<c1;
     cout<<"\n"<<c2;   
     cout<<"\n"<<c1-c2;                             
     getch();
}
Exemplo n.º 19
0
Arquivo: avltree.c Projeto: iAlaska/ds
/*Find maxmum element in T*/
Position
FindMax(AVLTree T){
	if(T == NULL)
		return NULL;
	else
	if(T->Right == NULL)
		return T;
	else
		return FindMax(T->Right);
}
Exemplo n.º 20
0
Position FindMax(AvlTree t)
{
    if(t == NULL){
        return NULL; 
    }
    if(t->right != NULL){
        return FindMax(t->right); 
    }else{
        return t; 
    }
}
treeNode* FindMax(treeNode *node)
{
        if(node==NULL)
        {
                /* There is no element in the tree */
                return NULL;
        }
        if(node->right) /* Go to the left sub tree to find the min element */
                FindMax(node->right);
        else 
                return node;
}
Exemplo n.º 22
0
Position FindMax(SearchTree T)//找到树中的最大值,并返回位置指针
{
	if(T==null)
	{
		printf("错误:二叉树为空");
		return null;
	}
	else if(T->Right==null)
			return T;
		else
			return FindMax(T->Right);
}
Exemplo n.º 23
0
void CLoadMapGraph::FindHeavierLoads()
{
	for (int from = 0; from < m_roads.size(); ++from)
	{
		for (int to = 0; to < m_roads.size(); ++to)
		{
			if (m_roads[from][to] != -1)
			{
				m_towns[to] = FindMax(FindMin(m_roads[from][to], m_towns[from]), m_towns[to]);
			}
		}
	}
}
Exemplo n.º 24
0
void Insert(ElementType X, PriorityQueue H) {
    int i;

    
    
    if (X.rmsd > FindMax(H).rmsd) return;
    
    if (IsFull(H)) DeleteMax(H);
    

    for (i = ++H->Size; H->Elements[ i / 2 ].rmsd < X.rmsd; i /= 2)
        H->Elements[ i ] = H->Elements[ i / 2 ];
    H->Elements[ i ] = X;
}
int main()
{
	int a[MAX][MAX];
	int row, col;
	printf("\nInput row: ");
	scanf("%d", &row);
	printf("\nInput colume: ");
	scanf("%d", &col);
	
	Input(a, row, col);
	Output(a, row, col);
	printf("\nMax: %d", FindMax(a, row, col));
	
	return 0;
}
Exemplo n.º 26
0
Position FindMax(SearchTree T)
{
	if (T == NULL)
	{
		return NULL;
	}
	if (T->Right == NULL)
	{
		return T;
	}
	else
	{
		return FindMax(T->Right);
	}
}
Exemplo n.º 27
0
int main()
{
    AvlTree t = NULL; 
    Position p;
    t = Insert(1, t);
    t = Insert(2, t);
    t = Insert(5, t);
    p = Find(1, t);
    printf("p->e:%d\n", p->e);
    p = FindMin(t); 
    printf("Min:%d\n", p->e);
    p = FindMax(t);
    printf("Max:%d\n", p->e);
    return 0;
}
Exemplo n.º 28
0
int main(){
    SearchTree T;
    Position P;
    int i;
    int j = 0;
    T = MakeEmpty( NULL );
    for(i=0; i<50; i++, j = ( j + 7 )%50){
        printf("%d\n",j);
        T = Insert(j, T);
    }
    Position max ;
    max = FindMax(T);
   printf("max:%d\n", Retrieve(max));
   //error :
   // printf("max:%d\n", max->Element);
}
Exemplo n.º 29
0
int main()
{
	AvlTree TestTree = NULL;
	cout << "This is the test for Avl Tree." << endl;
	cout << "Notice:The print method is preorder traversal " << endl;
	cout << "First,insert some datas..." << endl;
	TestTree = Insert(9, TestTree);
	TestTree = Insert(5, TestTree);
	TestTree = Insert(10, TestTree);
	TestTree = Insert(0, TestTree);
	TestTree = Insert(6, TestTree);
	TestTree = Insert(11, TestTree);
	TestTree = Insert(-1, TestTree);
	TestTree = Insert(1, TestTree);
	TestTree = Insert(2, TestTree);
	PrintTree(TestTree);
	cout << "\nThe Min is " << Retrieve(FindMin(TestTree)) << endl;
	cout << "The Max is " << Retrieve(FindMax(TestTree)) << endl;
	cout << "Count Nodes: " << CountNodes(TestTree) << " Leaves: " 
		<< CountLeaves(TestTree) << " Full: " << CountFull(TestTree) << endl;
	cout << "Now delete 10(with one child node)..." << endl;
	TestTree = Delete(10, TestTree);
	PrintTree(TestTree);
	cout << "\nNow delete 11(with none child node)..." << endl;
	TestTree = Delete(11, TestTree);
	PrintTree(TestTree);
	cout << "\nNow delete 1(with two child node)..." << endl;
	TestTree = Delete(1, TestTree);
	PrintTree(TestTree);
	cout << "\nNow Print element between 5 and 10 in order " << endl;
	PrintKeyBetween(5, 10, TestTree);
	cout << "\nMake empty..." << endl;
	TestTree = MakeEmpty(TestTree);
	int Success = TestTree == NULL;
	cout << "Succeed? " << Success << endl;
	cout << "Now Generate the mininum tree with Height equal to 5" << endl;
	AvlTree MinH10 = MinAvlTree(5);
	PrintTree(MinH10);
	cout << "\nNow Generate the perfect tree with Height equal to 5" << endl;
	AvlTree PrefectH10 = PerfectAvlTree(5);
	PrintTree(PrefectH10);
	cout << "\nMake empty..." << endl;
	MinH10 = MakeEmpty(MinH10);
	PrefectH10 = MakeEmpty(PrefectH10);
	cout << "Good bye!" << endl;
	getchar();
}
Exemplo n.º 30
0
main( )
{
    SplayTree T;
    SplayTree P;
    int i;
    int j = 0;

    T = Initialize( );
    T = MakeEmpty( T );
    for( i = 0; i < NumItems; i++, j = ( j + 7 ) % NumItems )
        T = Insert( j, T );
  
    for( j = 0; j < 2; j++ )
        for( i = 0; i < NumItems; i++ )
        {
            T = Find( i, T );
            if( Retrieve( T ) != i )
                printf( "Error1 at %d\n", i );
        }

    printf( "Entering remove\n" );

    for( i = 0; i < NumItems; i += 2 )
        T = Remove( i, T );

    for( i = 1; i < NumItems; i += 2 )
    {
        T = Find( i, T );
        if( Retrieve( T ) != i )
            printf( "Error2 at %d\n", i );
    }

    for( i = 0; i < NumItems; i += 2 )
    {
        T = Find( i, T );
        if( Retrieve( T ) == i )
            printf( "Error3 at %d\n", i );
    }

    printf( "Min is %d\n", Retrieve( T = FindMin( T ) ) );
    printf( "Max is %d\n", Retrieve( T = FindMax( T ) ) );

    return 0;
}