xixi2


  • 首页

  • 关于

  • 标签

  • 分类

  • 归档

  • 搜索

mysql日志

发表于 2019-10-19 | 分类于 数据库

mysql日志记录了mysql的日常操作和错误信息,通过日志,我们可以知道mysql内部发生的事情,可以为mysql的管理和优化提供必要的信息。
mysql日志主要有:二进制日志、通用查询日志、慢查询日志、错误日志、事务日志。

阅读全文 »

SSL/TLS与https

发表于 2019-10-19 | 分类于 安全基础

加密方法可以分为两大类。一类是单钥加密(private key cryptography),还有一类叫做双钥加密(public key cryptography)。前者的加密和解密过程都用同一套密码,后者的加密和解密过程用的是两套密码。

阅读全文 »

TCP和UDP通信实例实现

发表于 2019-10-18 | 分类于 网络编程

首先实现一个简单的服务器端和客户端通信的小例子.

阅读全文 »

IO复用

发表于 2019-10-18 | 分类于 网络编程

IO复用是在阻塞IO基础上,通过某种机制同时对多个文件描述符进行监视的一种方式。

阅读全文 »

C++常用函数api

发表于 2019-10-18 | 分类于 C++基础知识

本文档主要整理并记录c++常用的api。

阅读全文 »

c++标准库

发表于 2019-10-18 | 分类于 C++基础知识

几个可以参考的网站:
http://www.cplusplus.com
https://en.cppreference.com/w
https://gcc.gnu.org

阅读全文 »

C++对象模型系列1

发表于 2019-10-18 | 分类于 C++对象模型

在C++对象模型中,Nonstatic data members被配置于每一个class object之内,static data members则被放在个别的class object之外。static和nonstatic function members也被放在个别的class object之外。

阅读全文 »

move语义

发表于 2019-10-18 | 分类于 C++基础知识

std::move

阅读全文 »

147. Insertion Sort List

发表于 2019-10-16 | 分类于 leetcode

Sort a linked list using insertion sort.

img
A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list.
With each iteration one element (red) is removed from the input data and inserted in-place into the sorted list

Algorithm of Insertion Sort:

  1. Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list.
  2. At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there.
  3. It repeats until no input elements remain.

Example 1:

1
2
Input: 4->2->1->3
Output: 1->2->3->4

Example 2:

1
2
Input: -1->5->3->4->0
Output: -1->0->3->4->5

解法1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* insertionSortList(ListNode* head) {
if(head == nullptr || head->next == nullptr){
return head;
}
ListNode* cur = head->next;
ListNode* prev = head;
while(cur!=nullptr){
if(head->val > cur->val){
prev->next = cur->next;
cur->next = head;
head = cur;
cur = prev->next;
}else{
ListNode* p = head;
while(p->next != cur && p->next->val <= cur->val){
p = p->next;
}
if(p->next != cur){
prev->next = cur->next;
cur->next = p->next;
p->next = cur;
cur = prev->next;
}else{
prev = cur;
cur = cur->next;
}
}
}
return head;
}
};

解法2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* insertionSortList(ListNode* head) {
if(head == nullptr || head->next == nullptr){
return head;
}

ListNode* pHead = head;
ListNode* p = head->next;
pHead->next = nullptr;
while(p){
ListNode* cur = pHead;
ListNode* tmp = p->next;

if(pHead->val > p->val){
p->next = pHead;
pHead = p;
}else{
while(cur->next != nullptr && cur->next->val <= p->val){
cur = cur->next;
}
p->next = cur->next;
cur->next = p;
}
p = tmp;
}
return pHead;
}
};

Reverse Linked List

发表于 2019-10-16
  1. Reverse Linked List
    阅读全文 »
1…678…18
xixi2

xixi2

一去不复返的远方还有无法抵达的过去

175 日志
21 分类
107 标签
© 2019 xixi2
由 Hexo 强力驱动
|
主题 — NexT.Mist v5.1.4
访问人数 总访问量 次