模拟路由器 //路由器,功能为:存储,转发即抓包,改变包的内容#include <stdio.h>#include <sys/socket.h>#include <netinet/ether.h>#include <arpa/inet.h>#include <string.h>#include <netpacket/packet.h>#include <sys/ioctl.h>#include <net/if.h&
set容器判断是否插入成功 set<int> sa; bool flag = sa.insert(1).second; bool flag2 = sa.insert(1).second; cout<<"flag="<<flag<<endl; cout<<"flag2="<<flag2<<endl;
二叉树求高度以及叶子节点数目 int btDepth(TreeNode* root){ if(NULL==root) return 0; int lh = btDepth(root->left); int rh = btDepth(root->right); int height = lh>rh?lh+1:rh+1; return height;}void leafNum(TreeNode* root,int* num){ if(NULL
将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 /** * struct ListNode { * int val; * struct ListNode *next; * }; */class Solution {public: /** * * @param l1 ListNode类 * @param l2 ListNode类 * @return ListNode类 */ ListNode* mergeTwoLists(ListNode* l1, ListNode*
两数的和(牛客) class Solution {public: /** * * @param numbers int整型vector * @param target int整型 * @return int整型vector */ vector<int> twoSum(vector<int>& numbers, int target) { // write code here v.
二叉树的前中后序遍历(牛客) /** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */class Solution {public: /** * * @param root TreeNode类 the root of binary tree * @return int整型vector<vector<>> */
set容器 set容器根据元素键值自动排序键值实值是同一个值键值不能相同迭代器不能改变键值底层是红黑树(父子之间黑红相间)#include <iostream>#include<set>using namespace std;void printSet(set<int>& s){ set<int>::iterator it = s.begin(); for(;it!=s.end();it++) { c.
非递归实现链表反转(无头节点) class Solution {public: ListNode* ReverseList(ListNode* pHead) { if(pHead==NULL||pHead->next==NULL) return pHead; else { //申请三个指针,1.当前指向2.返回指针3.当前指向的前一个 //ListNode* cur = pHead; ListNode*
数据库sqlite3操作3(c语言操作数据库) main.c#include<stdio.h>#include"sqlite3.h"//结果中每一行数据触发一次int my_fun(void* para,int n_column,char** column_value,char** column_name){ printf("####################"); int i = 0; for ( i = 0; i < n_column; i++) { print.
数据库sqlite3操作3 常用的约束分类:主键,唯一约束,检查约束主键:一个表中只有一个主键,主键修饰的列额值不允许重复联结表:视图:重用SQL语句,简化复杂的sql操作(简化联结表的语句)触发器:是数据库的回调函数,每当delete,insert,update 操作才会触发创建索引:...