Esempio n. 1
0
int main(void)
{
	int i;
	char *post, *order;
	btree *t;

	while (scanf("%d", &n) != EOF) {
		post = (char *)malloc(n);
		order = (char *)malloc(n);
		
		getchar();
		for (i = 0; i < n; i ++)
			scanf("%c", order + i);

		getchar();
		for (i = 0; i < n; i ++)
			scanf("%c", post + i);

		t = rebuildTree(order, post, n);

		preTraverse(t);
		printf("\n");

		free(post);
		free(order);

	}

	return 0;
}
Esempio n. 2
0
DeckListModel::DeckListModel(QObject *parent)
    : QAbstractItemModel(parent), lastKnownColumn(1), lastKnownOrder(Qt::AscendingOrder)
{
    deckList = new DeckLoader;
    connect(deckList, SIGNAL(deckLoaded()), this, SLOT(rebuildTree()));
    connect(deckList, SIGNAL(deckHashChanged()), this, SIGNAL(deckHashChanged()));
    root = new InnerDecklistNode;
}
Esempio n. 3
0
DeckListModel::DeckListModel(QObject *parent)
    : QAbstractItemModel(parent)
{
    deckList = new DeckLoader;
    connect(deckList, SIGNAL(deckLoaded()), this, SLOT(rebuildTree()));
    connect(deckList, SIGNAL(deckHashChanged()), this, SIGNAL(deckHashChanged()));
    root = new InnerDecklistNode;
}
Esempio n. 4
0
void DeckViewScene::setDeck(const DeckList &_deck)
{
    if (deck)
        delete deck;
    
    deck = new DeckList(_deck);
    rebuildTree();
    applySideboardPlan(deck->getCurrentSideboardPlan());
    rearrangeItems();
}
Esempio n. 5
0
/**
 * 中序、后序序列构建二叉树
 */
btree* rebuildTree(char *order, char *post, int len)
{
	btree *t;

	if (len <= 0) {
		return NULL;
	} else {
		int index = 0;

		while (index < len && *(post + len - 1) != *(order + index)) {
			index ++;
		}	

		t = (btree *)malloc(sizeof(btree));
		t->data = *(order + index);
		t->lchild = rebuildTree(order, post, index);
		t->rchild = rebuildTree(order + index + 1, post + index, len - (index + 1));
	}

	return t;
}
Esempio n. 6
0
bool ScriptsModel::parseXML(QByteArray xmlFile) {
    beginResetModel();

    QXmlStreamReader xml(xmlFile);
    QRegExp jsRegex(".*\\.js");
    bool truncated = false;
    QString lastKey;

    while (!xml.atEnd() && !xml.hasError()) {
        if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name() == IS_TRUNCATED_NAME) {
            while (!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == IS_TRUNCATED_NAME)) {
                xml.readNext();
                if (xml.text().toString() == "true") {
                    truncated = true;
                }
            }
        }

        if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name() == CONTAINER_NAME) {
            while (!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == CONTAINER_NAME)) {
                if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name() == KEY_NAME) {
                    xml.readNext();
                    lastKey = xml.text().toString();
                    if (jsRegex.exactMatch(xml.text().toString())) {
                        QString localPath = lastKey.split("/").mid(1).join("/");
                        QUrl fullPath = defaultScriptsLocation();
                        fullPath.setPath(fullPath.path() + lastKey);
                        const QString fullPathStr = normalizeScriptURL(fullPath).toString();
                        _treeNodes.append(new TreeNodeScript(localPath, fullPathStr, SCRIPT_ORIGIN_DEFAULT));
                    }
                }
                xml.readNext();
            }
        }
        xml.readNext();
    }
    rebuildTree();
    endResetModel();

    // Error handling
    if (xml.hasError()) {
        qCDebug(scriptengine) << "Error loading default scripts: " << xml.errorString();
        return true;
    }

    if (truncated) {
        requestDefaultFiles(lastKey);
    }

    // If this request was not truncated, we are done.
    return !truncated;
}
Esempio n. 7
0
void Tree::rebuildOriginalFile(char *pathIn)
{
    string info, aux_s,aux_s2;
    ifstream file;
    unsigned char* buffer;

    info.clear();


    rebuildTree(tree_written);
    //printNo(root);
    equilibrar(tree_written);

    file.open(pathIn, ios::in | ios::binary | ios::ate);

    if(file.is_open()){
        int size = file.tellg();
        file.seekg(0, ios::beg);

        buffer = new unsigned char[size];

        for(int i = 0; i < parada; i++){
            file.get();
        }

        for(int i = parada;i < size-1;i++){
            unsigned char ch = file.get();
            const unsigned char c = (const unsigned char)ch;
            info += charParaString(c);
        }

        aux_s = info;

        const char c = file.get();

        aux_s2 = charParaString(c);
        removeTrash(aux_s2);
        aux_s += aux_s2;
        procurafinal(aux_s);


    }
    else
    {
        cout << "TRASH!" << endl;
    }

    file.close();

}
Esempio n. 8
0
File: tree.cpp Progetto: blaws/Tree
void keyboard( unsigned char key, int x, int y )
{
    switch( key )
    {
        case 'i':
        case 'I':
            cameraR -= 0.5;
            if( cameraR < 0.5 )
            {
                cameraR = 0.5;
            }
            break;
        case 'o':
        case 'O':
            cameraR += 0.5;
            break;
            
        case 'a':
        case 'A':
            --lookAt.z;
            break;
        case 's':
        case 'S':
            ++lookAt.z;
            break;
            
        case 'r':
        case 'R':
            rebuildTree();
            sendData();
            setView();
            break;
            
        case 'w':
        case 'W':
            wireFrame = !wireFrame;
            glPolygonMode( GL_FRONT_AND_BACK, wireFrame ? GL_LINE : GL_FILL );
            break;
            
        case 033:  // ESC
        case 'q':
        case 'Q':
            exit( EXIT_SUCCESS );
    }
    
    setView();
    glutPostRedisplay();
}
Esempio n. 9
0
bool ScriptsModel::parseXML(QByteArray xmlFile) {
    beginResetModel();

    QXmlStreamReader xml(xmlFile);
    QRegExp jsRegex(".*\\.js");
    bool truncated = false;
    QString lastKey;

    while (!xml.atEnd() && !xml.hasError()) {
        if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name() == IS_TRUNCATED_NAME) {
            while (!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == IS_TRUNCATED_NAME)) {
                xml.readNext();
                if (xml.text().toString() == "true") {
                    truncated = true;
                }
            }
        }

        if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name() == CONTAINER_NAME) {
            while (!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == CONTAINER_NAME)) {
                if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name() == KEY_NAME) {
                    xml.readNext();
                    lastKey = xml.text().toString();
                    if (jsRegex.exactMatch(xml.text().toString())) {
                        _treeNodes.append(new TreeNodeScript(lastKey.mid(MODELS_LOCATION.length()), S3_URL + "/" + lastKey, SCRIPT_ORIGIN_REMOTE));
                    }
                }
                xml.readNext();
            }
        }
        xml.readNext();
    }
    rebuildTree();
    endResetModel();

    // Error handling
    if (xml.hasError()) {
        qDebug() << "Error loading remote scripts: " << xml.errorString();
        return true;
    }

    if (truncated) {
        requestRemoteFiles(lastKey);
    }

    // If this request was not truncated, we are done.
    return !truncated;
}
Esempio n. 10
0
void HTree::getSizeThings(QByteArray code)
{
    my_fileCode = code;  
    for(int i = 0; i < 24; i++){
        if(i <= 2){
            if(getBit(i)){
                s_Trash += 0x1 << (2-i);
            }
        }
        else if(i <= 15){
            if(getBit(i)){
                s_Tree += 0x1 << (15-i);
            }
        }
        else{
            if(getBit(i)){
                s_Name += 0x1 << (23-i);
            }
        }
    }
    for(int i = 3; i < 3 + s_Name; i++){
        my_fileName += (unsigned char)my_fileCode.at(i);
    }
    for(int i = 3 + s_Name; i < 3 + s_Name + s_Tree; i++){
        my_treeCode.append((unsigned char)my_fileCode.at(i));
    }

    my_fileCode.remove(0,3+s_Name+s_Tree);
    setRoot(rebuildTree(this->my_treeCode));
    m_cursor = m_root;

    for(long long int i = 0; i < (long long int)((my_fileCode.size()*8) - s_Trash); i++){
        if(getBit(i)){
            toRight();
        }
        else{
            toLeft();
        }
        if(m_cursor->isLeaf()){
            my_finalOutPut += (unsigned char)m_cursor->content;
            m_cursor = m_root;
        }
    }


}
Esempio n. 11
0
BookmarkList::BookmarkList( Okular::Document *document, QWidget *parent )
    : QWidget( parent ), m_document( document ), m_currentDocumentItem( 0 )
{
    QVBoxLayout *mainlay = new QVBoxLayout( this );
    mainlay->setMargin( 0 );
    mainlay->setSpacing( 6 );

    m_searchLine = new KTreeWidgetSearchLine( this );
    mainlay->addWidget( m_searchLine );

    m_tree = new QTreeWidget( this );
    mainlay->addWidget( m_tree );
    QStringList cols;
    cols.append( "Bookmarks" );
    m_tree->setContextMenuPolicy(  Qt::CustomContextMenu );
    m_tree->setHeaderLabels( cols );
    m_tree->setSortingEnabled( false );
    m_tree->setRootIsDecorated( true );
    m_tree->setAlternatingRowColors( true );
    m_tree->setItemDelegate( new PageItemDelegate( m_tree ) );
    m_tree->header()->hide();
    m_tree->setSelectionBehavior( QAbstractItemView::SelectRows );
    m_tree->setEditTriggers( QAbstractItemView::EditKeyPressed );
    connect( m_tree, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(slotExecuted(QTreeWidgetItem*)) );
    connect( m_tree, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotContextMenu(QPoint)) );
    m_searchLine->addTreeWidget( m_tree );

    QToolBar * bookmarkController = new QToolBar( this );
    mainlay->addWidget( bookmarkController );
    bookmarkController->setObjectName( QLatin1String( "BookmarkControlBar" ) );
    // change toolbar appearance
    bookmarkController->setIconSize( QSize( 16, 16 ) );
    bookmarkController->setMovable( false );
    QSizePolicy sp = bookmarkController->sizePolicy();
    sp.setVerticalPolicy( QSizePolicy::Minimum );
    bookmarkController->setSizePolicy( sp );
    // insert a togglebutton [show only bookmarks in the current document]
    m_showBoomarkOnlyAction = bookmarkController->addAction( KIcon( "bookmarks" ), i18n( "Current document only" ) );
    m_showBoomarkOnlyAction->setCheckable( true );
    connect( m_showBoomarkOnlyAction, SIGNAL(toggled(bool)), this, SLOT(slotFilterBookmarks(bool)) );

    connect( m_document->bookmarkManager(), SIGNAL(bookmarksChanged(KUrl)), this, SLOT(slotBookmarksChanged(KUrl)) );

    rebuildTree( m_showBoomarkOnlyAction->isChecked() );
}
Esempio n. 12
0
void ScriptsModel::reloadLocalFiles() {
    beginResetModel();

    for (int i = _treeNodes.size() - 1; i >= 0; i--) {
        TreeNodeBase* node = _treeNodes.at(i);
        if (node->getType() == TREE_NODE_TYPE_SCRIPT &&
            static_cast<TreeNodeScript*>(node)->getOrigin() == SCRIPT_ORIGIN_LOCAL)
        {
            delete node;
            _treeNodes.removeAt(i);
        }
    }

    _localDirectory.refresh();

    const QFileInfoList localFiles = _localDirectory.entryInfoList();
    for (int i = 0; i < localFiles.size(); i++) {
        QFileInfo file = localFiles[i];
        _treeNodes.append(new TreeNodeScript(file.fileName(), file.absoluteFilePath(), SCRIPT_ORIGIN_LOCAL));
    }
    rebuildTree();
    endResetModel();
}
Esempio n. 13
0
//Reconstrói o arquivo original
void Tree::rebuildOriginalFile(char *pathIn)
{
    std::string info, aux_s,aux_s2;
    std::ifstream file;
    std::string oux, oux2;
    int sobra2 = 0;
    unsigned char* buffer;
    int x = 0;

    info.clear();



    rebuildTree(tree_written);

    //printNo(root);


    equilibrar(tree_written);



    file.open(pathIn, std::ios::in | std::ios::binary | std::ios::ate);


    if(file.is_open())
    {
        int size = file.tellg();
        file.seekg(0, std::ios::beg);

        buffer = new unsigned char[size];

        for(int i = 0; i < parada; i++)
        {
            file.get();
        }



        for(int i = parada;i < size-1;i++)
        {
            unsigned char ch = file.get();
            const unsigned char c = (const unsigned char)ch;



            info += charParaString(c);
            //ajeitar



            /*
        if(info.length() == 1024)
        {
            //sobra2 = info.length() - 1024;
            //oux = info.substr(1024, sobra2);
            //oux2 = info.substr(0,1024);

            aux_s = procura(info,&x);

            cout << "aux_s size: " << aux_s.length() << endl;
            info.clear();

            info += aux_s;
            //info += oux;

            aux_s.clear();
            //oux.clear();
            //oux2.clear();
        }
        */

        }



        //x = info.length();

        int sobra = 1024 - info.length();

        //aux_s = info.substr(x,sobra);
        aux_s = info;



        const char c = file.get();

        aux_s2 = charParaString(c);

        removeTrash(aux_s2);

        aux_s += aux_s2;


        //        cout << "aux_s: ";
        //        for(int i = 0; i < aux_s.length();i++)
        //        {
        //            cout << aux_s[i] << " ";
        //            if((i-1)%8 == 0 && i != 0)
        //            {
        //                cout << endl;
        //                cout << "aux_s: ";
        //            }
        //        }

        procurafinal(aux_s);


    }
    else
    {
        cout << "eRRO!" << endl;
    }

    file.close();

}
Esempio n. 14
0
void DeckViewScene::resetSideboardPlan()
{
    rebuildTree();
    rearrangeItems();
}
Esempio n. 15
0
void DeckListModel::setDeckList(DeckList *_deck)
{
	delete deckList;
	deckList = _deck;
	rebuildTree();
}
Esempio n. 16
0
void BookmarkList::slotFilterBookmarks( bool on )
{
    rebuildTree( on );
}
Esempio n. 17
0
void GraphicsLayerUpdater::rebuildTree(RenderLayer& layer, GraphicsLayerVector& childLayersOfEnclosingLayer)
{
    // Make the layer compositing if necessary, and set up clipping and content layers.
    // Note that we can only do work here that is independent of whether the descendant layers
    // have been processed. computeCompositingRequirements() will already have done the repaint if necessary.

    layer.stackingNode()->updateLayerListsIfNeeded();

    const bool hasCompositedLayerMapping = layer.hasCompositedLayerMapping();
    CompositedLayerMappingPtr currentCompositedLayerMapping = layer.compositedLayerMapping();

    // If this layer has a compositedLayerMapping, then that is where we place subsequent children GraphicsLayers.
    // Otherwise children continue to append to the child list of the enclosing layer.
    GraphicsLayerVector layerChildren;
    GraphicsLayerVector& childList = hasCompositedLayerMapping ? layerChildren : childLayersOfEnclosingLayer;

#if !ASSERT_DISABLED
    LayerListMutationDetector mutationChecker(layer.stackingNode());
#endif

    if (layer.stackingNode()->isStackingContainer()) {
        RenderLayerStackingNodeIterator iterator(*layer.stackingNode(), NegativeZOrderChildren);
        while (RenderLayerStackingNode* curNode = iterator.next())
            rebuildTree(*curNode->layer(), childList);

        // If a negative z-order child is compositing, we get a foreground layer which needs to get parented.
        if (hasCompositedLayerMapping && currentCompositedLayerMapping->foregroundLayer())
            childList.append(currentCompositedLayerMapping->foregroundLayer());
    }

    RenderLayerStackingNodeIterator iterator(*layer.stackingNode(), NormalFlowChildren | PositiveZOrderChildren);
    while (RenderLayerStackingNode* curNode = iterator.next())
        rebuildTree(*curNode->layer(), childList);

    if (hasCompositedLayerMapping) {
        bool parented = false;
        if (layer.renderer()->isRenderPart())
            parented = RenderLayerCompositor::parentFrameContentLayers(toRenderPart(layer.renderer()));

        if (!parented)
            currentCompositedLayerMapping->parentForSublayers()->setChildren(layerChildren);

        // If the layer has a clipping layer the overflow controls layers will be siblings of the clipping layer.
        // Otherwise, the overflow control layers are normal children.
        if (!currentCompositedLayerMapping->hasClippingLayer() && !currentCompositedLayerMapping->hasScrollingLayer()) {
            if (GraphicsLayer* overflowControlLayer = currentCompositedLayerMapping->layerForHorizontalScrollbar()) {
                overflowControlLayer->removeFromParent();
                currentCompositedLayerMapping->parentForSublayers()->addChild(overflowControlLayer);
            }

            if (GraphicsLayer* overflowControlLayer = currentCompositedLayerMapping->layerForVerticalScrollbar()) {
                overflowControlLayer->removeFromParent();
                currentCompositedLayerMapping->parentForSublayers()->addChild(overflowControlLayer);
            }

            if (GraphicsLayer* overflowControlLayer = currentCompositedLayerMapping->layerForScrollCorner()) {
                overflowControlLayer->removeFromParent();
                currentCompositedLayerMapping->parentForSublayers()->addChild(overflowControlLayer);
            }
        }

        if (shouldAppendLayer(layer))
            childLayersOfEnclosingLayer.append(currentCompositedLayerMapping->childForSuperlayers());
    }
}