コード例 #1
0
void OrdListClass<ItemType>::rFill
	( /* In */	   node<ItemType>* trav,	// A traversal pointer
	  /* In/Out */ ItemType arr[],			// The array to fill
	  /* In */	   int index )				// The index of the array at which to assign a value
{
	// If the index is less than the number of elements in the array
	if( index < MAX_ITEMS )
	{
		// If the traversal pointer is not NULL
		if( trav != NULL )
		{
			arr[ index ] = trav->data;

			// Fill the array with the data in the nodes of the traversal pointer's left subtree
			rFill( trav->left, arr, 2 * index + 1 );

			// Fill the array with the data in the nodes of the traversal pointer's right subtree
			rFill( trav->right, arr, 2 * index + 2 );

		} // End if
		// Else the traversal pointer is NULL
		else
			arr[ index ].key = INT_MAX;

	} // End if

} // End rFill( node* trav, ItemType arr[], int index )
コード例 #2
0
void GraphicsMisc::DrawRect(CDC* pDC, const CRect& rect, COLORREF crFill, COLORREF crBorder, int nCornerRadius, DWORD dwEdges)
{
	if (rect.IsRectEmpty())
		return;

	if (nCornerRadius == 0)
	{
		// can't have border color and no edges
		if (dwEdges == 0)
			crBorder = CLR_NONE;

		// if both colours are set there's an optimisation we can do
		if ((crFill != CLR_NONE) && (crBorder != CLR_NONE))
		{
			pDC->FillSolidRect(rect, crBorder);

			if (crFill != crBorder)
			{
				CRect rFill(rect);

				if ((dwEdges & GMDR_ALL) == GMDR_ALL)
				{
					rFill.DeflateRect(1, 1);
				}
				else
				{
					if (dwEdges & GMDR_LEFT)
						rFill.left++;

					if (dwEdges & GMDR_TOP)
						rFill.top++;

					if (dwEdges & GMDR_RIGHT)
						rFill.right--;

					if (dwEdges & GMDR_BOTTOM)
						rFill.bottom--;
				}

				pDC->FillSolidRect(rFill, crFill);
			}
		}
		else if (crFill != CLR_NONE) // inside of rect
		{
			pDC->FillSolidRect(rect, crFill);
		}
		else if (crBorder != CLR_NONE) // border
		{
			if (dwEdges & GMDR_TOP)
				pDC->FillSolidRect(rect.left, rect.top, rect.Width(), 1, crBorder);

			if (dwEdges & GMDR_BOTTOM)
				pDC->FillSolidRect(rect.left, rect.bottom - 1, rect.Width(), 1, crBorder);

			if (dwEdges & GMDR_LEFT)
				pDC->FillSolidRect(rect.left, rect.top, 1, rect.Height(), crBorder);

			if (dwEdges & GMDR_RIGHT)
				pDC->FillSolidRect(rect.right - 1, rect.top, 1, rect.Height(), crBorder);
		}
	}
	else // round-rect
	{
		CPen* pOldPen = NULL, penBorder;
		CBrush* pOldBrush = NULL, brFill;

		// inside of rect
		if (crFill != CLR_NONE)
		{
			brFill.CreateSolidBrush(crFill);
			pOldBrush = pDC->SelectObject(&brFill);
		}

		// border
		if (crBorder != CLR_NONE)
		{
			penBorder.CreatePen(PS_SOLID, 1, crBorder);
			pOldPen = pDC->SelectObject(&penBorder);
		}

		pDC->RoundRect(rect, CPoint(nCornerRadius, nCornerRadius));

		// cleanup
		pDC->SelectObject(pOldBrush);
		pDC->SelectObject(pOldPen);
	}
}
コード例 #3
0
void OrdListClass<ItemType>::PrintAsExists
	( /* In */ FunctionType visit )	// A pointer to the function defined by the client which determines
									//  what happens when the traversal visits a node
{
	ItemType arr[ MAX_ITEMS ];	// Copies of the data at each node in the tree

	// For each index in the array
	for( int i = 0; i < MAX_ITEMS; i++ )
		arr[ i ].key = INT_MIN;

	// Recursively fill the array so hat the items at each sequential index of the array are copies of
	//  the items that appear in a breadth-first traversal of the tree
	rFill( root, arr, 0 );
	
	// For each index in the array
	for( int i = 0; i < MAX_ITEMS; i++ )
	{
		// If the index is less than one
		if( i < 1 )
		{
			cout << "                                      ";

			// If the key of the item at the index is equal to INT_MAX
			if( arr[ i ].key == INT_MAX )
				cout << "  #  ";
			// Else if the key of the item at the index is not equal to INT_MIN
			else if( arr[ i ].key != INT_MIN )
				visit( arr[ i ] );
			// Else the key of the item at the index is equal to INT_MIN
			else
				cout << "     ";

			cout << endl;

		} // End if
		// Else if the index is less than three
		else if( i < 3 )
		{
			// If the index is equal to one
			if( i == 1 )
				cout << "                  ";
			// Else the index is not equal to one
			else
				cout << "                                   ";

			// If the key of the item at the index is equal to INT_MAX
			if( arr[ i ].key == INT_MAX )
				cout << "  #  ";
			// Else if the key of the item at the index is not equal to INT_MIN
			else if( arr[ i ].key != INT_MIN )
				visit( arr[ i ] );
			// Else the key of the item at the index is equal to INT_MIN
			else
				cout << "     ";

			// If the index is equal to two
			if( i == 2 )
				cout << endl;

		} // End else if
		// Else if the index is less than seven
		else if( i < 7 )
		{
			// If the index is equal to three
			if( i == 3 )
				cout << "        ";
			// Else the index is not equal to three
			else
				cout << "               ";

			// If the key of the item at the index is equal to INT_MAX
			if( arr[ i ].key == INT_MAX )
				cout << "  #  ";
			// Else if the key of the item at the index is not equal to INT_MIN
			else if( arr[ i ].key != INT_MIN )
				visit( arr[ i ] );
			// Else the key of the item at the index is equal to INT_MIN
			else
				cout << "     ";

			// If the index is equal to six
			if( i == 6 )
				cout << endl;

		} // End else if
		// Else if the index is less than fifteen
		else if( i < 15 )
		{
			// If the index is equal to seven
			if( i == 7 )
				cout << "   ";
			// Else if the index is not equal to seven
			else
				cout << "     ";
			
			// If the key of the item at the index is equal to INT_MAX
			if( arr[ i ].key == INT_MAX )
				cout << "  #  ";
			// Else if the key of the item at the index is not equal to INT_MIN
			else if( arr[ i ].key != INT_MIN )
				visit( arr[ i ] );
			// Else the key of the item at the index is equal to INT_MIN
			else
				cout << "     ";

			// If the index is equal to fourteen
			if( i == 14 )
				cout << endl;

		} // End else if
		// Else if the index is less than thirty-one
		else if( i < 31 )
		{
			// If the key of the item at the index is equal to INT_MAX
			if( arr[ i ].key == INT_MAX )
				cout << "  #  ";
			// Else if the key of the item at the index is not equal to INT_MIN
			else if( arr[ i ].key != INT_MIN )
				visit( arr[ i ] );
			// Else the key of the item at the index is equal to INT_MIN
			else
				cout << "     ";

		} // End else if

	} // End for

	cout << endl;

} // End PrintAsExists( FunctionType visit )