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; }
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); }
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); } }
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; }
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);
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; }
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; }
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; }
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 ; }
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; } }