Beispiel #1
0
void DisplayTree(SearchTree T) {
    if(T != NULL) {
        printf("%d	",T->element);
        DisplayTree(T->left);
        DisplayTree(T->right);
    }
}
Beispiel #2
0
int main()
{
    /* Constructed binary tree is
                7
              /   \
            8      2
          /  \    / \
        3     5  1   9
          \
            4
    */
    struct node *root = newNode(7);
    root->left        = newNode(8);
    root->right       = newNode(2);
    root->left->left  = newNode(3);
    root->left->right = newNode(5);
    root->right->left = newNode(1);
    root->right->right  = newNode(9);
    root->left->left->right = newNode(4);
    DisplayTree(root);

    /* Constructed binary tree is
                9
              /   \
            5     18
          /  \    / \
         2    7  16  23
          \
            4
    */
    struct node *root1  = newNode(9);
    root1->right        = newNode(18);
    root1->left         = newNode(5);
    root1->right->right = newNode(23);
    root1->right->left  = newNode(16);
    root1->left->right  = newNode(7);
    root1->left->left   = newNode(2);
    root1->left->left->right = newNode(4);
    DisplayTree(root1);

    if(TreesAreQuasiIsomorphic(root, root1)){
        printf("\nBoth trees are Quasi-Isomorphic.");
    } else{
        printf("\nBoth trees are not Quasi-Isomorphic.");
    }

    return 0;
}
Beispiel #3
0
FILE_ITEM CFileTree::AddItem(char *absolutePath, unsigned char* handle)
{
	FILE_ITEM item;
	item.handle = handle;
	item.bCached = false;

	if (filesTree.empty()) {
		item.path = new char[strlen(absolutePath) + 1];
		strcpy_s(item.path, (strlen(absolutePath) + 1), absolutePath);
		item.nPathLen = strlen(item.path);

		filesTree.set_head(item);
		topNode = filesTree.begin();
	}
	else {
		std::string sPath(absolutePath);
		tree_node_<FILE_ITEM>* parentNode = findParentNodeFromRootForPath(absolutePath);
		std::string splittedPath = sPath.substr(sPath.find_last_of('\\') + 1);
		item.path = new char[splittedPath.length() + 1];
		strcpy_s(item.path, (splittedPath.length() + 1), splittedPath.c_str());
		if (parentNode) {
			filesTree.append_child(tree<FILE_ITEM>::iterator_base(parentNode), item);
		} else {
			//printf("Parent node found for %s", absolutePath);
		}
	}

	DisplayTree(topNode.node, 0);

	return item;
}
Beispiel #4
0
void CFileTree::RemoveItem(char *absolutePath)
{
	tree_node_<FILE_ITEM>* node = findNodeFromRootWithPath(absolutePath);
	if (node != NULL) {
		filesTree.erase(tree<FILE_ITEM>::iterator(node));
	}
	else {
		//printf("Do not find node for path : %s\n", absolutePath);
	}

	DisplayTree(topNode.node, 0);
}
Beispiel #5
0
CDeviceConfig::CDeviceConfig(QWidget* mainWnd, QWidget *parent) :
    QFrame(parent),
    ui(new Ui::CDeviceConfig)
{
    ui->setupUi(this);
    pParent = dynamic_cast< MainWindow* > ( mainWnd );
    CCommonFunction::ConnectCloseButton( ui->lblClose );
    pCurItem = NULL;
    pMenu = NULL;

    pSetting = CCommonFunction::GetSettings( CommonDataType::CfgDevice );
    //ReadFile( );

    DisplayTree( );
    ui->lblTitle->setText( windowTitle( ) );
}
Beispiel #6
0
void DisplayTree(tree_node_<FILE_ITEM>* node, int level)
{
	if (CFileTree::debug) {
		printf("\n\n\n<<<<<<<<<<<<<<<<<<<<<DISPLAY tree \n\n\n");
		tree<FILE_ITEM>::sibling_iterator  sib2 = filesTree.begin(node);
		tree<FILE_ITEM>::sibling_iterator  end2 = filesTree.end(node);
		while (sib2 != end2) {
			for (int i = 0; i < level; i++) {
				printf("  ");
			}
			if (tree<FILE_ITEM>::number_of_children(sib2) > 1) {
				DisplayTree(sib2.node, (level + 1));
			}
			++sib2;
		}
		printf("\n\n\n<<<<<<<<<<<<<<<<<<<<<End tree \n\n\n");
	}
}
Beispiel #7
0
FILE_ITEM CFileTree::AddItem(char *absolutePath, unsigned char* handle)
{
	FILE_ITEM item;
	item.handle = handle;
	item.bCached = false;

	// If the tree is empty just add the new path as node on the top level.
	if (filesTree.empty()) {
		item.path = new char[strlen(absolutePath) + 1];
		strcpy_s(item.path, (strlen(absolutePath) + 1), absolutePath);
		item.nPathLen = strlen(item.path);

		filesTree.set_head(item);
		topNode = filesTree.begin();
	}
	else {
		// Check if the requested path belongs to an already registered parent node.
		std::string sPath(absolutePath);
		tree_node_<FILE_ITEM>* parentNode = findParentNodeFromRootForPath(absolutePath);
		std::string splittedPath = _basename_932(sPath);
		//printf("spl %s %s\n", splittedPath.c_str(), absolutePath);
		item.path = new char[splittedPath.length() + 1];
		strcpy_s(item.path, (splittedPath.length() + 1), splittedPath.c_str());
		// If a parent was found use th parent.
		if (parentNode) {
			//printf("parent %s\n", parentNode->data.path);
			filesTree.append_child(tree<FILE_ITEM>::iterator_base(parentNode), item);
		} else {
			// Node wasn't found - most likely a new root - add it to the top level.
			//printf("No parent node found for %s. Adding new sibbling.", absolutePath);
			item.path = new char[strlen(absolutePath) + 1];
			strcpy_s(item.path, (strlen(absolutePath) + 1), absolutePath);
			item.nPathLen = strlen(item.path);
			
			filesTree.insert(tree<FILE_ITEM>::iterator_base(topNode), item);
			topNode = filesTree.begin();
		}
	}

	DisplayTree(topNode.node, 0);

	return item;
}
Beispiel #8
0
CDeviceConfig::CDeviceConfig(QWidget* mainWnd, QWidget *parent) :
    QFrame(parent),
    ui(new Ui::CDeviceConfig)
{
    ui->setupUi(this);
    pParent = dynamic_cast< MainWindow* > ( mainWnd );
    CCommonFunction::ConnectCloseButton( ui->lblClose );
    pCurItem = NULL;
    pMenu = NULL;

    pSetting = CCommonFunction::GetSettings( CommonDataType::CfgSystem );
    bNocardMode = pSetting->value( "CommonCfg/SenseOpenGate", false ).toBool( );// &&
            //pSetting->value( "CommonCfg/NoCardWork", false ).toBool( );

    pSetting = CCommonFunction::GetSettings( CommonDataType::CfgDevice );
    //ReadFile( );

    DisplayTree( );
    ui->lblTitle->setText( windowTitle( ) );
}
Beispiel #9
0
int main()
{
    FILE *InputFile=fopen("#InputText.in","r");
    FILE *EncodedFile=fopen("#Output.out","w");
    FILE *CodesFile=fopen("#Keys.out","w");
    FILE *TreeFile=fopen("#Tree.out","w");
    FILE *DecodedFile=fopen("#Decoded.out","w");
    FILE *CompressionFile=fopen("#CRatio.out","w");

	TEXT INPUT[MAX_LEN],OUTPUT[ENCODE_LEN];
	ReadFile(InputFile);
    Huffman(INPUT);
    PrintCodes(CodesFile);
    DisplayTree(&ROOT , LEVEL , TreeFile);                         // Display the Huffman Tree
    DisplayTreeLevels(&ROOT , TreeFile);                           // Display the Huffman Tree by Levels
    HuffmanEncoding(INPUT , OUTPUT);                            // Input -<Encoding>-> Encoded Sequence
    EncodeFile(EncodedFile);
    DecodingHuffman(OUTPUT , TreeTop , DecodedFile);           // Encoded Sequence -<Decoding>-> Decoded Sequence
    compressionRatio(INPUT , OUTPUT , CompressionFile);
	return 0;
}
Beispiel #10
0
void CFileTree::RenameItem(char *absolutePathFrom, char *absolutePathTo)
{
	tree_node_<FILE_ITEM>* node = findNodeFromRootWithPath(absolutePathFrom);
	tree_node_<FILE_ITEM>* parentNode = findParentNodeFromRootForPath(absolutePathTo);

	if (parentNode != NULL && node != NULL) {
		if (filesTree.number_of_children(parentNode) < 1) {
			FILE_ITEM emptyItem;
			emptyItem.nPathLen = 0;
			emptyItem.path = const_cast<char*>("");
			filesTree.append_child(tree<FILE_ITEM>::iterator_base(parentNode), emptyItem);
		}
		tree<FILE_ITEM>::iterator firstChild = filesTree.begin(parentNode);
		filesTree.move_after(firstChild, tree<FILE_ITEM>::iterator(node));

		std::string sPath(absolutePathTo);
		std::string splittedPath = sPath.substr(sPath.find_last_of('\\') + 1);
		node->data.path = new char[splittedPath.length() + 1];
		strcpy_s(node->data.path, (splittedPath.length() + 1), splittedPath.c_str());

	}
	DisplayTree(topNode.node, 0);
}