上一页 1 2 3 4 5 6 7 8 ··· 10 下一页
摘要: 模板函数在编译时才创建,开始时并不会创建 类型做模板的参数 #include<iostream> #include<vector> #include<string> template<typename T> void Print(T value){ std::cout<<value<<std::en 阅读全文
posted @ 2023-09-12 19:02 iu本u 阅读(23) 评论(0) 推荐(0)
摘要: 这样会使用复制构造函数6次;push_back()是往后推,会复制一份 struct Vectex{ float x,y,z; Vectex(float x,float y,float z) :x(x),y(y),z(z) {} Vectex(const Vectex& Vectex) :x(Vec 阅读全文
posted @ 2023-09-12 18:15 iu本u 阅读(37) 评论(0) 推荐(0)
摘要: 使用深度优先遍历构造的图,只要访问过就标记已访问 int num=0; vector<bool>vis; void dfs(vector<vector<int>>& rooms,int x){ vis[x]=true; num++; for(auto& v:rooms[x]){ if(!vis[v] 阅读全文
posted @ 2023-09-12 13:49 iu本u 阅读(11) 评论(0) 推荐(0)
摘要: 删除的二叉树节点分4种情况: 叶子节点,直接删除就行 左节点不为空,右节点为空;直接将左子树返回 左节点为空,右节点不为空;直接将右子树返回 左节点和右节点不为空;将右子树最小的节点作为根节点,返回右子树 TreeNode* deleteNode(TreeNode* root, int key) { 阅读全文
posted @ 2023-09-12 13:09 iu本u 阅读(12) 评论(0) 推荐(0)
摘要: 智能指针中de-> class Entity{ public: int x; public: void Print(){ std::cout<<"Hello Entity!"<<std::endl; } }; class scopedPtr{ private: Enity* m_Entity; pu 阅读全文
posted @ 2023-09-07 14:56 iu本u 阅读(12) 评论(0) 推荐(0)
摘要: 使用智能指针删除堆上分配的内存,而不用delete class Entity{ public: int x; public: void Print(){ std::cout<<"Hello Entity!"<<std::endl; } }; class scopedPtr{ private: Eni 阅读全文
posted @ 2023-09-07 14:52 iu本u 阅读(12) 评论(0) 推荐(0)
摘要: class String{ private: char* m_Buffer; unsigned int m_Size; public: String(const char* string){//首先const char* 等同于string m_Size=int(strlen(string));// 阅读全文
posted @ 2023-09-05 16:49 iu本u 阅读(21) 评论(0) 推荐(0)
摘要: 唯一指针不能复制,它的参数不能使用new关键字创建。 std::unique_ptr<Entity>entity=std::make_unique<Entity>(); std::unique_ptr<Entity>e0=entity; 共享指针有一个引用计数,当计数为0就宣布释放内存。 { std 阅读全文
posted @ 2023-09-05 15:52 iu本u 阅读(29) 评论(0) 推荐(0)
摘要: dfs lass Solution { public: unordered_map<int,vector<int>>m; void dfs(TreeNode* root,int depth){ if(!root)return; int res=0; depth++; dfs(root->left,d 阅读全文
posted @ 2023-09-05 15:02 iu本u 阅读(22) 评论(0) 推荐(0)
摘要: 前序遍历:中左右(先遍历左子树);中右左(先遍历右子树) 中序遍历:左中右; 后序遍历:左右中; 本题递归: vector<int>v;//记录最先遍历到的右子树 void dfs(TreeNode* root,int depth){ if(!root)return ; if(v.size()==d 阅读全文
posted @ 2023-09-04 16:34 iu本u 阅读(11) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 ··· 10 下一页