bool MirrorImage(TreeNode* pRootNode, TreeNode* pLeftSubTree, TreeNode* pRightSubTree)
{
	bool bRetValue = false;
	TreeNode* pLeft =NULL, *pRight = NULL;
	
	if ( !pRootNode ) return false;

	if ( pLeftSubTree )
		pLeft= pLeftSubTree;
	else
		pLeft = pRootNode->pLeft;

	if ( pRightSubTree )
		pRight = pRightSubTree;
	else
		pRight = pRootNode->pRight;

	if (pLeft && pRight)
	{
		if ( pLeft->data == pRight->data )
			bRetValue = true;
		else 
		{
			bRetValue = false;
			goto Error;
		}
	}
	else
	{
		bRetValue = false;
		goto Error;
	}

	if ( pLeft->pLeft && pRight->pRight)
	{
		bRetValue = MirrorImage(pRootNode, pLeft->pLeft, pRight->pRight);
		if ( !bRetValue )
			goto Error;
	}
	else if ( pLeft->pRight && pRight->pLeft)
	{
		bRetValue = MirrorImage(pRootNode, pLeft->pRight, pRight->pLeft);
		if ( !bRetValue )
			goto Error;
	}
	else
	{
		printf("Tree is Mirror Image tree...");
		bRetValue= true;
	}
Error:
	return bRetValue;
}
Esempio n. 2
0
void TopLevel::mirrorPage()
{
  if(!thispage || !Image || !faxqtwin || !display_is_setup)
    return;

  XDefineCursor(qtdisplay, Win, WorkCursor);
  XFlush(qtdisplay);

  XImage *newmirror = MirrorImage(Images[0]);

  XDefineCursor(qtdisplay, Win, ReadyCursor);

  if(newmirror == NULL){ // out of memory
    return;
  }
  thispage->extra = Images[0] = newmirror;
  thispage->orient ^= TURN_M;

  freeImages();
  Image = generateZoomImages(oz);

  Refresh = Resize = 1;
  putImage();
}
Esempio n. 3
0
void SCH_EDIT_FRAME::OnOrient( wxCommandEvent& aEvent )
{
    SCH_SCREEN* screen = GetScreen();
    SCH_ITEM*   item   = screen->GetCurItem();

    INSTALL_UNBUFFERED_DC( dc, m_canvas );

    // Allows block rotate operation on hot key.
    if( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK )
    {
        if( aEvent.GetId() == ID_SCH_MIRROR_X )
        {
            m_canvas->MoveCursorToCrossHair();
            screen->m_BlockLocate.SetMessageBlock( this );
            screen->m_BlockLocate.SetCommand( BLOCK_MIRROR_X );
            HandleBlockEnd( &dc );
        }
        else if( aEvent.GetId() == ID_SCH_MIRROR_Y )
        {
            m_canvas->MoveCursorToCrossHair();
            screen->m_BlockLocate.SetMessageBlock( this );
            screen->m_BlockLocate.SetCommand( BLOCK_MIRROR_Y );
            HandleBlockEnd( &dc );
        }
        else
        {
            wxFAIL_MSG( wxT( "Unknown block oriention command ID." ) );
        }

        return;
    }

    if( item == NULL )
    {
        // If we didn't get here by a hot key, then something has gone wrong.
        if( aEvent.GetInt() == 0 )
            return;

        EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject();

        wxCHECK_RET( data != NULL, wxT( "Invalid hot key client object." ) );

        item = LocateAndShowItem( data->GetPosition(), SCH_COLLECTOR::OrientableItems,
                                  aEvent.GetInt() );

        // Exit if no item found at the current location or the item is already being edited.
        if( (item == NULL) || (item->GetFlags() != 0) )
            return;
    }


    switch( item->Type() )
    {
    case SCH_COMPONENT_T:
        if( aEvent.GetId() == ID_SCH_MIRROR_X )
            OrientComponent( CMP_MIRROR_X );
        else if( aEvent.GetId() == ID_SCH_MIRROR_Y )
            OrientComponent( CMP_MIRROR_Y );
        else if( aEvent.GetId() == ID_SCH_ORIENT_NORMAL )
            OrientComponent( CMP_NORMAL );
        else
            wxFAIL_MSG( wxT( "Invalid orient schematic component command ID." ) );

        break;

    case SCH_BITMAP_T:
        if( aEvent.GetId() == ID_SCH_MIRROR_X )
            MirrorImage( (SCH_BITMAP*) item, true );
        else if( aEvent.GetId() == ID_SCH_MIRROR_Y )
            MirrorImage( (SCH_BITMAP*) item, false );

        break;

    default:
        wxFAIL_MSG( wxString::Format( wxT( "Schematic object type %s cannot be oriented." ),
                                      GetChars( item->GetClass() ) ) );
    }

    if( item->GetFlags() == 0 )
        screen->SetCurItem( NULL );
}
int main()
{
	__pTrieHead = new TrieTreeNode();

	InsertValue(__pTrieHead, "truck");
	InsertValue(__pTrieHead, "trick");
	InsertValue(__pTrieHead, "trunck");
	InsertValue(__pTrieHead, "trash");
	InsertValue(__pTrieHead, "tank");

	/*FindWord(__pTrieHead, "tank");
	FindWord(__pTrieHead, "truck");
	FindWord(__pTrieHead, "trick");
	FindWord(__pTrieHead, "trunck");
	FindWord(__pTrieHead, "trash");

	FindWord(__pTrieHead, "trudt");*/

	FindWordByPrefix(__pTrieHead, "t");

	getch();
	FreeTrieTree(__pTrieHead);
	return 1;

/* Derived d;
	Base* b1 = &d;
	Base& b2 = d;
	Base b3;*/

	/*AccessVTable clAccessVTable;

	int* vptrBase = (int*)&clAccessVTable;
	getch();
	return 0;

	fn1();*/

	// Late binding for both:
	/*cout << "b1->f() = " << b1->f() << endl;
	cout << "b2.f() = " << b2.f() << endl;

	// Early binding (probably):
	cout << "b3.f() = " << b3.f() << endl;

	cout << "VPTR's Address " << (int*)(&d+0) << endl;
	cout << "virtual tables's Address " << (int*)*(int*)(&d+0) << endl; // Value of VPTR
	cout << "Value at first entry of VIRTUAL TABLE " << (int*)*(int*)*(int*)(&d+0) << endl;

	Fun pFun = (Fun)*(int*)*(int*)(&d+0);   // calling Virtual function
	pFun();
	d.fnDisplay();

	/*Derived* pDerivedPtr = new Derived[10];
	Derived* pTempDptr;
	pTempDptr = (pDerivedPtr+5);
	delete [] pTempDptr;

	int i=10;
	int & iRef = i;

	/*Temp *pTemp = new Temp;

	//Allocate memoty for 2Dimensional array and assign value to it...
	Temp** ppTemp = new Temp*[10];

	for ( i =0 ; i < 10 ; i++ )
		ppTemp[i] = new Temp;
	
	memset(ppTemp, 0 , 10 * sizeof (Temp));

	for ( i =0 ; i < 10 ; i++ )
	{
		delete ppTemp[i];
		ppTemp[i] = NULL;
	}
	delete []ppTemp;
	//Allocation of 2D arary on heap ends...



	//Difference between passing reference and pointers as function argument...
	{
		Temp t1;
		t1.iInt = 10;

		//call copy constructor...
		Temp t2 = t1;

		//call pointered copy constructor...
		Temp t3(&t2);
	}
	//Ends...
	
	*/
	//getch();
	char ch='\0';
	int option=0, iValue=0, iDirection=-1;
	do
	{
		printf("\n*****************************");
		printf("\n\tTREE OPERATIONS");
		printf("\n*****************************");
		printf("\n1.Insert Node Element");
		printf("\n2.Delete Node Element");
		printf("\n3.Search Node Element");
		printf("\n4.Find Node Element");
		printf("\n5.InOrder Traversal");
		printf("\n6.PreOrder Traversal");
		printf("\n7.PostOrder Traversal");
		printf("\n8.Is Mirror Image");
		printf("\n9.BFS Traversal");
		printf("\n10.DFS Traversal");
		printf("\n11.Create Mirror Image Tree");
		printf("\n12.Release Tree Nodes");
		printf("\n13.Terminate");
		printf("\n*****************************");
		printf("\nEnter Option : ");
		scanf("%d",&option);
		
		switch ( option )
		{
		case 1:
			{
				printf("\nEnter value:");
				scanf("%d", &iValue);
				InsertTreeNode(&__pRoot, iValue);
			}
			break;
		case 2:
			break;
		case 3:
			{
				clock_t StartTime, EndTime;
				float micro=0.0, seconds=0.0;
				printf("\nEnter value to search:");
				scanf("%d", &iValue);
				StartTime = clock();
				if (!SearchTreeNode(__pRoot, iValue))
					printf("\nNOT FOUND...!!!");
				EndTime= clock();
				micro = ((float)StartTime- (float)EndTime);
				printf("\nTime taken to perform search operation is [%f] microseconds", micro);
				printf("\nTime taken to perform search operation is [%f] seconds", seconds);
			}
			break;
		case 4:
			break;
		case 5:
			{
				TraverseTree_InOrder(__pRoot);
			}
			break;
		case 6:
			{
				TraverseTree_PreOrder(__pRoot);
			}
			break;
		case 7:
			{
				TraverseTree_PostOrder(__pRoot);
			}
			break;

		case 8:
			{
				if ( MirrorImage(__pRoot, NULL, NULL))
					printf("\nTree is Mirro Image.");
				else	
					printf("\nTree is not Mirror Image");
			}	
		break;
		case 9:
			{
				TraverseTree_PostOrder(__pRoot);
			}
		break;
		case 10:
			{
				TraverseTree_PostOrder(__pRoot);
			}
		break;
		case 11:
			{
				printf("\nEnter value:");
				scanf("%d", &iValue);
				printf("\nEnter direction [LEFT =1, RIGHT=1]:");
				scanf("%d", &iDirection);
				CreateMirrorImageTree(&__pRoot, iValue, iDirection);
			}
		break;
		case 12:
			{
				ReleaseTreeNodes(&__pRoot);
					//__pRoot = NULL;
			}
			break;
		}
	}
	while (option<13);
	ReleaseTreeNodes(&__pRoot);
	return 1;
}