void AdvHuffman::Update(int T, bool baru) /* Update pohon saat menginput node baru. T merupakan node baru yang diinput atau frequensi node lama yang ditambah*/ { int P; if (baru){ P = TabNode[T].getParent(); while (TabNode[P].getParent() != -1){ int MaxNumber = MaxNumberNodeInBlock(P); if (MaxNumber != P){ switchNode(P,MaxNumber); UpdateNomorNode(); } int L = TabNode[P].getLeft(); int R = TabNode[P].getRight(); TabNode[P].setWeight(TabNode[L].getWeight() + TabNode[R].getWeight()); P = TabNode[P].getParent(); } } else { // Proses untuk mengolah T int MaxNumber = MaxNumberNodeInBlock(T); if ((MaxNumber != T) && (MaxNumber != TabNode[T].getParent())){ switchNode(T,MaxNumber); UpdateNomorNode(); } TabNode[T].setWeight(TabNode[T].getWeight()+1); P = TabNode[T].getParent(); P = TabNode[T].getParent(); while (TabNode[P].getParent() != -1){ int MaxNumber = MaxNumberNodeInBlock(P); if (MaxNumber != P){ switchNode(P,MaxNumber); UpdateNomorNode(); } int L = TabNode[P].getLeft(); int R = TabNode[P].getRight(); TabNode[P].setWeight(TabNode[L].getWeight() + TabNode[R].getWeight()); P = TabNode[P].getParent(); } } }
void RecursiveCFGBuilder::visit(ShPtr<SwitchStmt> stmt) { ShPtr<CFG::Node> beforeSwitchNode(currNode); // Create a node for the switch statement. ShPtr<CFG::Node> switchNode(new CFG::Node()); firstStmtNodeMapping[stmt] = switchNode; cfg->stmtNodeMapping[stmt] = switchNode; switchNode->stmts.push_back(stmt); cfg->addNode(switchNode); cfg->addEdge(beforeSwitchNode, switchNode); // Create a node for each clause. for (auto i = stmt->clause_begin(), e = stmt->clause_end(); i != e; ++i) { ShPtr<CFG::Node> clauseBody(addNode(i->second)); ShPtr<Expression> cond; if (i->first) { // Generate a label of the form `switchCond == clauseCond`. cond = EqOpExpr::create(stmt->getControlExpr(), i->first); } else { cond = generateSwitchDefaultCondLabel(stmt); } cfg->addEdge(switchNode, clauseBody, cond); } // Create a node (an edge) for the switch's successor. However, if there is // a default clause, we don't have to do this. Indeed, if the default // clause always ends with a return statement, the statement's successor is // never entered. If the default clause doesn't always end with a return // statement, then the statement's successor has been already traversed // when a node for the default clause was added. if (stmt->hasDefaultClause()) { return; } if (ShPtr<Statement> stmtSucc = stmt->getSuccessor()) { ShPtr<CFG::Node> afterSwitchNode(addNode(stmtSucc)); cfg->addEdge(switchNode, afterSwitchNode); return; } currNode = switchNode; addForwardOrBackwardEdge(stmt); }
BinaryTree* deleteNode2(int val, BinaryTree *tree) { BinaryTree *res=NULL; res = malloc(sizeof(BinaryTree)); if(haveNode(val,tree))//condition : le noeud est present { if(nodeValue(tree)==val)// on se deplace dans le branches de l'arbre { // on supprime le noeud val dans l'arbre ou a été échangé val et le noeud de valeur maximale dans le sous arbre gauche res=deleteNode1(val,switchNode(val,maxNode(leftChild(tree)),tree)); } else// appel recursif { res=createNodeWithChilds(deleteNode2(val,leftChild(tree)),nodeValue(tree),deleteNode2(val,rightChild(tree))); } } else { res=tree; } return res; }