Ejemplo n.º 1
0
main(int argc, char *argv[]) {
    node gnd;
    node n1("n1");
    node n2("n2");
    node n3("n3");
    node n4("n4");
    node n5("n5");
    node n6("n6");

    vdc vcc("vcc", n6, gnd, 5.0);
    vpulse vin("vin", n1, gnd, 0, 5, 2e-9, 2e-9, 2e-9, 10e-9);
    r rb1("rb1", n1, n2, 10e3);
    r rc1("rc1", n6, n3, 1e3);
    qnd q1("q1", n3, n2, gnd);
    r rb2("rb2", n3, n4, 10e3);
    qnd q2("q2", n5, n4, gnd);
    r rc2("rc2", n6, n5, 1e3);

    op::monitor = 1;
    op();

    plot::output = *argv;
    plot::add("n1", "n3", "n5");

    tran::tsmin = 1.0e-30;
    tran::monitor = 1;
    tran(0.2e-9, 20.0e-9);
}
int main(int argc, char const *argv[])
{
	// 	     0
	// 	    / \
	//     1   2
	//    / \   \
	//   3   4   7
	//        \  /
	//         5 8
	//          \
	//           6
	TreeNode<int> n0(0);
	TreeNode<int> n1(1);
	TreeNode<int> n2(2);
	TreeNode<int> n3(3);
	TreeNode<int> n4(4);
	TreeNode<int> n5(5);
	TreeNode<int> n6(6);
	TreeNode<int> n7(7);
	TreeNode<int> n8(8);
	n0.left = &n1;
	n0.right = &n2;
	n1.left = &n3;
	n1.right = &n4;
	n4.right = &n5;
	n5.right = &n6;
	n2.right = &n7;
	n7.left = &n8;

	bool* matrix = solve(&n0);
	delete[] matrix;

	return 0;
}
int main(int argc, char* argv[])
{
    Solution s;
    
    ListNode n1(1);
    ListNode n3(3);
    ListNode n5(5);
    ListNode n2(2);
    ListNode n4(4);
    ListNode n6(6);
    n1.next = &n3;
    n3.next = &n5;
    n2.next = &n4;
    n4.next = &n6;

    ListNode *ret1 = s.mergeTwoLists(&n1, &n2);
    int i = 0;
    while (ret1 != NULL)
    {
        i++;
        assert(ret1->val == i);
        ret1 = ret1->next;
    }

    i = 2;
    ret1 = s.mergeTwoLists(&n1, NULL);
    while (ret1 == NULL)
    {
        assert(ret1->val == 2);
        i += 2;
        ret1 = ret1->next;
    }

    return 0;
}
TEST(removeNthFromEnd, caseTest) {
    Solution s;
    
    ListNode n0(0);
    EXPECT_EQ(NULL, s.removeNthFromEnd(&n0, 1));
    
    ListNode n1(1);
    ListNode n2(2);
    n1.next = &n2;
    ListNode* n3 = s.removeNthFromEnd(&n1, 2);
    EXPECT_EQ(&n2, n3);
    EXPECT_EQ(NULL, n3->next);
    
    ListNode n4(4);
    ListNode n5(5);
    ListNode n6(6);
    ListNode n7(7);
    n4.next = &n5;
    n5.next = &n6;
    n6.next = &n7;
    ListNode *n8 = s.removeNthFromEnd(&n4, 4);
    EXPECT_EQ(5, n8->val);
    EXPECT_EQ(6, n8->next->val);
    
}
Ejemplo n.º 5
0
main()
{
P1DIR = 0xFF;
while(1)
	{
	n1();
	delay(65000);
	n2();
	delay(65000);
	n3();
	delay(65000);
	n4();
	delay(65000);
	n5();
	delay(65000);
	n6();
	delay(65000);
	n7();
	delay(65000);
	n8();
	delay(65000);
	n9();
	delay(65000);
	n0();
	delay(65000);
	}
}
Ejemplo n.º 6
0
int main() {
    TreeNode n1(5);
    TreeNode n2(4);
    TreeNode n3(8);
    TreeNode n4(11);
    TreeNode n5(13);
    TreeNode n6(4);
    TreeNode n7(7);
    TreeNode n8(2);
    TreeNode n9(1);

    n1.left = &n2;
    n1.right = &n3;

    n2.left = &n4;
    n4.left = &n7;
    n4.right = &n8;

    n3.left = &n5;
    n3.right = &n6;

    n6.right = &n9;

    Solution sln;

    cout << sln.hasPathSum(&n1, 22) << endl;

    return 0;
}
Ejemplo n.º 7
0
int main(){
    node n1(1);
    node n2(2);
    node n3(3);
    node n4(4);
    node n5(5);
    node n6(6);
    node n7(7);
    node n8(8);
    node n9(9);
    node n10(10);
Ejemplo n.º 8
0
int main() {
    // init data
    TreeNode n6(6);
    TreeNode n2(2);
    TreeNode n8(8);
    TreeNode n0(0);
    TreeNode n4(4);
    TreeNode n7(7);
    TreeNode n9(9);
    TreeNode n3(3);
    TreeNode n5(5);

    n6.left = &n2;
    n6.right = &n8;

    n2.left = &n0;
    n2.right = &n4;

    n8.left = &n7;
    n8.right = &n9;

    n4.left = &n3;
    n4.right = &n5;

    // 测试 fillMapParents
    Solution sol;
    map<TreeNode*, TreeNode*> mapParents;
    sol.fillMapParents(&n6, mapParents);
    sol.printMapParents(mapParents);

    // 测试 depth
    sol.printAllNodesDepth(mapParents, &n6);

    // 测试 traverseUpward
    TreeNode* tempNode = &n2;
    sol.traverseUpward(tempNode, 1, mapParents);

    // 测试 lowestCommonAncestor
    TreeNode* v = &n2;
    TreeNode* w = &n4;
    TreeNode* lca = sol.lowestCommonAncestor(&n6, v, w);
    cout << endl << v->val << ", " << w->val << " 的 LCA 是 " << lca->val << endl << endl;

    v = &n2;
    w = &n8;
    lca = sol.lowestCommonAncestor(&n6, v, w);
    cout << endl << v->val << ", " << w->val << " 的 LCA 是 " << lca->val << endl << endl;

    return 0;
}
Ejemplo n.º 9
0
int main() {

    typedef DAG::Node<const idpair> INode;

    // create a set of nodes
    // the nodes will be kept track of in the Node children and parent collections so
    // shared_ptr is used.
    INode n0(idpair(0, 2));
    INode n1(idpair(1, 3));
    INode n2(idpair(2, 3));
    INode n3(idpair(3, 2));
    INode n4(idpair(4, 2));
    INode n5(idpair(5, 2));
    INode n6(idpair(6, 2));
    // and now define the polytree
    // add the directed (parent -> child) branches of the polytree
    // each link requires an addChild and an addParent
    n0.addChild(n1);  // link between n0 and n1
    n1.addChild(n2);  // link between n0 and n2 etc
    n1.addChild(n3);
    n3.addChild(n6);
    n3.addChild(n4);
    n4.addChild(n5);
    n5.addChild(n6);

    DAG::BFSRecurseVisitor<INode> bfs;
    // Start at node 0 for the following examples

    // Example 1
    // BFSVisitor uses an iterative method to traverse
    // output the Datatype of all children
    std::cout << std::endl << "TRAVERSE CHILDREN (start Node 0)  1 level" << std::endl;
    for (auto n : bfs.traverseChildren(n0, 1)) {
        std::cout << n->value().itype << ":" << n->value().ivalue << std::endl;
    }

    std::cout << std::endl << "TRAVERSE UNDIRECTED (start Node 5) 2 levels " << std::endl;
    for (auto n : bfs.traverseUndirected(n5, 2)) {
        std::cout << n->value().itype << ":" << n->value().ivalue << std::endl;
    }

    std::cout << std::endl << "TRAVERSE CHILDREN (start Node 0)  all levels" << std::endl;

    for (auto n : bfs.traverseChildren(n0)) {
        std::cout << n->value().itype << ":" << n->value().ivalue << std::endl;
    }

    return 0;
}
Ejemplo n.º 10
0
int main(){
    TreeNode n1(1);
    TreeNode n2(2);
    TreeNode n3(3);
    TreeNode n4(4);
    TreeNode n5(5);
    TreeNode n6(6);
    n1.left = &n2;
    //n1.right = &n5;
    n2.left = &n3;
    n2.right = &n4;
    n5.right = &n6;
    bool r = hasPathSum(&n1, 1);
    printf("%s\n", r?"true":"false");
    return 0;
}
int main() {
    
    {
        /*
        _______6______
       /              \
    ___2__          ___8__
   /      \        /      \
   0      _4       7       9
         /  \
         3   5
         */
        Node n1( 6 );
        Node n2( 2 );
        Node n3( 8 );
        Node n4( 0 );
        Node n5( 4 );
        Node n6( 7 );
        Node n7( 9 );
        Node n8( 3 );
        Node n9( 5 );

        n1.left  = &n2;
        n1.right = &n3;
        n2.left  = &n4;
        n2.right = &n5;
        n3.left  = &n6;
        n3.right = &n7;
        n5.left  = &n8;
        n5.right = &n9;

        const Node * p = lca_bst( &n1, &n8, &n9 );
        assert( p == &n5 );
        
        p = lca_bst( &n1, &n2, &n8 );
        assert( p == &n2 );
        
        p = lca_bst( &n1, &n7, &n9 );
        assert( p == &n1 );

        Node n10( 10 );
        p = lca_bst( &n1, &n2, &n10 );
        assert( p == nullptr );
    }
    
    return 0;
}
Ejemplo n.º 12
0
int main() {
    std::vector<ListNode*> lists;
    readFromFile(lists, "klist.txt");
    ListNode n1(1), n2(2), n1a(1), n3(3), n4(4), n5(5), n6(6),  *result;
    n1.next = &n3;
    n2.next = &n4;
    n4.next = &n6;
    //lists.push_back(&n1);
    //lists.push_back(&n2);
    //lists.push_back(&n5);

    std::cout << "Calling solution" << std::endl;
    Solution s;
    result = s.mergeKLists(lists);
    s.print(result);
    return 0;
}
Ejemplo n.º 13
0
int main()
{
	ListNode n6(10);
	ListNode n7(3);
	ListNode n8(45);
	ListNode n9(1);
	ListNode n10(38);
	ListNode n11(89);

	n6.next = &n7;
	n7.next = &n8;
	n8.next = &n9;
	n9.next = &n10;
	n10.next = &n11;

	ListNode* n = reverseList(&n6);

	while(n)
	{
		printf("%d->", n->val);
		n = n->next;
	}
    return 0;
}
Ejemplo n.º 14
0
void sctensdigit(int a) //ten's place
{
 s=30;
 xnxt=400-45;
 ynxt=100;
 w9=w8=w4=w6=w5=w2=w3=w7=w0=wk=we=wf=wj=wl=wp=wr=ws=s/2;//1/2
 w1=wi=s/4;
 wg=wc=wh=wn=wb=wu=wt=wv=wx=wy=2*s/3;//2/3
 ww=wm=wa=wd=wo=wq=wz=3*s/4;//3/4
 h=s;//1
glColor3f(0,0,0);
glPointSize(2.0);
switch(a)
{
case 0:n0(xnxt,ynxt,h,w0);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 1:n1(xnxt,ynxt,h,w1);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 2: n2(xnxt,ynxt,h,w2);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 3: n3(xnxt,ynxt,h,w3);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 4: n4(xnxt,ynxt,h,w4);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 5: n5(xnxt,ynxt,h,w5);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 6: n6(xnxt,ynxt,h,w6);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 7: n7(xnxt,ynxt,h,w7);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 8: n8(xnxt,ynxt,h,w8);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 9: n9(xnxt,ynxt,h,w9);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

default: break;
}
glFlush();
return ;
}
Ejemplo n.º 15
0
//  This is test for onedAST.py
int main(int argc, char** argv)
{
    int     npt     = 20;       // No. points to sample on test printing
    int     k       = 5;        // order of wavelet
    double  thresh  = 1e-12;    // truncation threshold

    // Step. 1          (Done!!!!)
    FunctionAST f1(k, thresh, test1);
    FunctionAST f2(k, thresh, test2);
    FunctionAST f4(k, thresh, sinn);
    
    // Step. 2
    f1.func->compress(0, 0);
    f2.func->compress(0, 0);
   
    //dic_print_tree(f1.func->s, "f1");
    //dic_print_tree(f2.func->s, "f2");
    //dic_print_tree(f4.func->s, "f4");

    // Step. 3
    FunctionAST resultAST(k, thresh, NULL);
    FunctionAST newresult(k, thresh, NULL);
  
    // Step. 4
    Node n0(&f1, 0, 0, 0, 0, 0, 0);
    Node n1(&f2, 0, 0, 0, 0, 0, 0);
    Node n2(&f2, 0, 0, 0, 0, 0, 0);
    Node n4(&f4, 0, 0, 0, 0, 0, 0);
    Node n6(&f4, 0, 0, 0, 0, 0, 0);

    // Step. 5
    // Reconstruct ASTs n1, n2, n22, n3
    AST* ast01 = ast_create_item(2,  NULL,   NULL);
    AST* ast02 = ast_create_item(0,  &n0,    NULL);
    ast_insert_item(ast02, ast01);

    AST* ast11 = ast_create_item(2,  NULL,   NULL);
    AST* ast12 = ast_create_item(0,  &n1,    NULL);
    ast_insert_item(ast12, ast11);

    AST* ast21 = ast_create_item(2, NULL,    NULL);
    AST* ast22 = ast_create_item(0, &n2,     NULL);
    ast_insert_item(ast22, ast21);
    
    // Step. 6
    AST* ast51 = ast_create_item(3,  NULL,   NULL);
    AST* ast52 = ast_create_item(0,  &n6,    NULL);
    ast_insert_item(ast52, ast51);

    // Create a full AST that computes (f1 + f2) * (f2 + f4 + diff(f4))
    // AST_ADD0 = [0, AST0, AST2]
    AST* add01 = ast_create_item(0,  NULL,   NULL);
    AST* add02 = ast_create_item(0,  NULL,   ast01);
    AST* add03 = ast_create_item(0,  NULL,   ast21);
    ast_insert_item(add02, add01);
    ast_insert_item(add03, add01);

    // AST_ADD1 = [0, AST1, n4, AST5]
    AST* add11 = ast_create_item(0,  NULL,   NULL);
    AST* add12 = ast_create_item(0,  NULL,   ast11);
    AST* add13 = ast_create_item(0,  &n4,    NULL);
    AST* add14 = ast_create_item(0,  NULL,   ast51);
    ast_insert_item(add12, add11);
    ast_insert_item(add13, add11);
    ast_insert_item(add14, add11);

    // AST_MUL  = [1, AST_ADD0, AST_ADD1]
    AST* mul1 = ast_create_item(1,  NULL,   NULL);
    AST* mul2 = ast_create_item(0,  NULL,   add01);
    AST* mul3 = ast_create_item(0,  NULL,   add11);
    ast_insert_item(mul2, mul1);
    ast_insert_item(mul3, mul1); 

    // Compute using onsedAST
    resultAST.traverse_tree(mul1, 0, 0);    
    printf ("\nAfter computing using onsedAST\n");
   
    //dic_print_tree_python(resultAST.func->s, 0, 0);

    // Compute (f1 + f2) * (f2 + f4 + diff(f4)) using original madpy without AST
    FunctionAST*    r_add0;
    FunctionAST*    r_add1;
    FunctionAST*    r_diff  = new FunctionAST(k, thresh, NULL);
    FunctionAST*    r_add5;
    FunctionAST*    r_prod;
    FunctionAST*    df;

    //dic_print_tree_python(f4.func->s, 0, 0);

    r_add0          = f1 + &f2;
    r_add1          = f2 + &f4;
    r_diff->func    = f4.func->diff(0, 0, NULL);
    r_add5          = *r_add1 + r_diff;
    r_prod          = *r_add0 * r_add5;
    r_prod->func->reconstruct(0, 0);

    df              = resultAST - r_prod;
    printf ("Norm of Difference is %12.8f\n", df->func->norm2());
}
void
dmz::StarfighterPluginSpaceBoxOSG::_create_box () {

   const String ImageName (_rc.find_file (_imgRc));

   osg::ref_ptr<osg::Image> img =
      (ImageName ? osgDB::readImageFile (ImageName.get_buffer ()) : 0);

   if (img.valid ()) {

      osg::Geode* geode = new osg::Geode ();

      osg::Geometry* geom = new osg::Geometry;

      osg::Vec4Array* colors = new osg::Vec4Array;
      colors->push_back (osg::Vec4 (1.0f, 1.0f, 1.0f, 1.0f));
      geom->setColorArray (colors);
      geom->setColorBinding (osg::Geometry::BIND_OVERALL);

      osg::StateSet *stateset = geom->getOrCreateStateSet ();
      stateset->setMode (GL_BLEND, osg::StateAttribute::ON);

#if 0
      osg::ref_ptr<osg::Material> material = new osg::Material;

      material->setEmission (
         osg::Material::FRONT_AND_BACK,
         osg::Vec4 (1.0, 1.0, 1.0, 1.0));

      stateset->setAttributeAndModes (material.get (), osg::StateAttribute::ON);
#endif

      osg::Texture2D *tex = new osg::Texture2D (img.get ());
      tex->setWrap (osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT);
      tex->setWrap (osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT);

      stateset->setTextureAttributeAndModes (0, tex, osg::StateAttribute::ON);

      stateset->setAttributeAndModes (new osg::CullFace (osg::CullFace::BACK));

      osg::Vec3Array *vertices = new osg::Vec3Array;
      osg::Vec2Array *tcoords = new osg::Vec2Array;
      osg::Vec3Array* normals = new osg::Vec3Array;

      const float Off (_offset);

      osg::Vec3 v1 (-Off, -Off, -Off);
      osg::Vec3 v2 ( Off, -Off, -Off);
      osg::Vec3 v3 ( Off,  Off, -Off);
      osg::Vec3 v4 (-Off,  Off, -Off);
      osg::Vec3 v5 (-Off, -Off,  Off);
      osg::Vec3 v6 ( Off, -Off,  Off);
      osg::Vec3 v7 ( Off,  Off,  Off);
      osg::Vec3 v8 (-Off,  Off,  Off);

      osg::Vec3 n1 ( 1.0,  1.0,  1.0);
      osg::Vec3 n2 (-1.0,  1.0,  1.0);
      osg::Vec3 n3 (-1.0, -1.0,  1.0);
      osg::Vec3 n4 ( 1.0, -1.0,  1.0);
      osg::Vec3 n5 ( 1.0,  1.0, -1.0);
      osg::Vec3 n6 (-1.0,  1.0, -1.0);
      osg::Vec3 n7 (-1.0, -1.0, -1.0);
      osg::Vec3 n8 ( 1.0, -1.0, -1.0);

      n1.normalize ();
      n2.normalize ();
      n3.normalize ();
      n4.normalize ();
      n5.normalize ();
      n6.normalize ();
      n7.normalize ();
      n8.normalize ();

//      const float F1 (5.0f);
//      const float F2 (2.5f);
      const float F1 (5.0f);
      const float F2 (2.5f);
      int count = 0;

      // 1
      vertices->push_back (v1);
      vertices->push_back (v2);
      vertices->push_back (v3);
      vertices->push_back (v4);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n1);
      normals->push_back (n2);
      normals->push_back (n3);
      normals->push_back (n4);
      count += 4;

      // 2
      vertices->push_back (v4);
      vertices->push_back (v3);
      vertices->push_back (v7);
      vertices->push_back (v8);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n4);
      normals->push_back (n3);
      normals->push_back (n7);
      normals->push_back (n8);
      count += 4;

      // 3
      vertices->push_back (v8);
      vertices->push_back (v7);
      vertices->push_back (v6);
      vertices->push_back (v5);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n8);
      normals->push_back (n7);
      normals->push_back (n6);
      normals->push_back (n5);
      count += 4;

      // 4
      vertices->push_back (v5);
      vertices->push_back (v6);
      vertices->push_back (v2);
      vertices->push_back (v1);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n5);
      normals->push_back (n6);
      normals->push_back (n2);
      normals->push_back (n1);
      count += 4;

      // 5
      vertices->push_back (v3);
      vertices->push_back (v2);
      vertices->push_back (v6);
      vertices->push_back (v7);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n3);
      normals->push_back (n2);
      normals->push_back (n6);
      normals->push_back (n7);
      count += 4;

      // 6
      vertices->push_back (v1);
      vertices->push_back (v4);
      vertices->push_back (v8);
      vertices->push_back (v5);
      tcoords->push_back (osg::Vec2 (0.0, 0.0));
      tcoords->push_back (osg::Vec2 (0.0, F1));
      tcoords->push_back (osg::Vec2 (F2, F1));
      tcoords->push_back (osg::Vec2 (F2, 0.0));
      normals->push_back (n1);
      normals->push_back (n4);
      normals->push_back (n8);
      normals->push_back (n5);
      count += 4;

      geom->setNormalArray (normals);
      geom->setNormalBinding (osg::Geometry::BIND_PER_VERTEX);
      geom->addPrimitiveSet (new osg::DrawArrays (GL_QUADS, 0, count));
      geom->setVertexArray (vertices);
      geom->setTexCoordArray (0, tcoords);
      geode->addDrawable (geom);

      _box = new osg::MatrixTransform ();

      _box->addChild (geode);
   }
   else { _log.error << "Failed to load: " << _imgRc << ":" << ImageName << endl; }
}