- 博客(4)
- 收藏
- 关注
原创 C++使用回车键结束while(cin>>)循环输入
用到C++的get()函数,不用在键盘上敲击Ctrl+Z,输入结束直接回车即可结束输入具体代码如下:#include <iostream>using namespace std;int main(){ int b = 0; char c; while ((cin >> b).get(c)) { cout << b << endl; if (c =='\n') break; } cout << "结束" <&l
2020-10-13 10:57:31
6107
转载 LRU缓存机制
LRU缓存机制LeetCode146官方题解struct DLinkedNode { int key, value; DLinkedNode* prev; DLinkedNode* next; DLinkedNode(): key(0), value(0), prev(nullptr), next(nullptr) {} DLinkedNode(int _key, int _value): key(_key), value(_value), prev(nullptr
2020-10-09 16:54:37
187
原创 C++快速排序与归并排序的实现(LeetCode 912)
快速排序//快速排序class Solution {public: int Partions(vector<int>& nums,int start,int end){ if(nums.size()==0||start<0||end>=nums.size()){ return 0; } int index=start;//随机数取每段的第一个元素即可 swap(nums[in
2020-10-09 16:30:40
296
原创 C++使用sort函数对vector的任意区间排序(某一段元素排序)
使用迭代器进行区间指定,注意start和end为前闭后开区间;sort函数内也可自行添加cmp比较函数,默认为从小到大排序。#include <vector>#include <algorithm>using namespace std;int main(){ vector<int>input = { 1, 5, 2, 1, 3, 2, 5 }; //排序整个vector //sort(input.begin(), input.end()); //对任意区
2020-10-08 16:08:23
4833
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人