sort std

C++面试八股文:std::deque用过吗?

某日二师兄参加XXX科技公司的C++工程师开发岗位第26面: > 面试官:`deque`用过吗? > > 二师兄:说实话,很少用,基本没用过。 > > 面试官:为什么? > > 二师兄:因为使用它的场景很少,大部分需要性能、且需要自动扩容的时候使用`vector`,需要随机插入和删除的时候可以使用` ......
八股文 八股 deque std

c++ std::execution::par,std::execution::par_unseq

#include <algorithm> #include <chrono> #include <cstdint> #include <execution> #include <iostream> #include <random> #include <vector> std::random_dev ......
execution std par par_unseq unseq

sort函数

在平常的排序过程中我么或许常常会犯难,遇到普通的数组或许还好,但是像结构体这样的数据多了难免会有些麻烦, 我查阅资料之后找到了一个函数这个函数是库里面自带的只需要头文件#include<algorithm> 下面讲讲详细用法,首先sort(a,a+n,cmp)它里面有三个变量 a代表我们的结构体的简 ......
函数 sort

【C/C++】排序函数sort()(基本数据类型&结构体排序)

库: #include<algorithm> sort函数原型(简化,能用就行): /* a和a+n是地址 对区间[a,a+n)中的元素进行排序,默认从小到大 可用cmp函数控制排序规则 */ sort(a,a+n,cmp){} 1.基本数据类型-修改排序规则-cmp函数 #include<iost ......
函数 类型 结构 数据 sort

Merge Sorted Array

You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in num ......
Sorted Merge Array

Faster sorting algorithms discovered using deep reinforcement learning

## 摘要: - `AlphaDev`模型优化排序算法,将排序算法提速70%。通过强化学习,AlphaDev发现了更加有效的算法,直接超越了科学家和工程师们几十年来的精心打磨。现在,新的算法已经成为两个标准C++编码库的一部分,每天都会被全球的程序员使用数万亿次。 ## 介绍 - 优化目标为排序算法 ......

C++面试八股文:std::array如何实现编译器排序?

某日二师兄参加XXX科技公司的C++工程师开发岗位第25面: > 面试官:`array`熟悉吗? > > 二师兄:你说的是原生数组还是`std::array`? > > 面试官:你觉得两者有什么区别? > > 二师兄:区别不是很大,原生数组(非动态数组)和std::array都在栈上开辟空间,初始化 ......
八股文 八股 编译器 array std

C++面试八股文:std::string是如何实现的?

# C++面试八股文:std::string是如何实现的? 某日二师兄参加XXX科技公司的C++工程师开发岗位第18面: > 面试官:`std::string`用过吧? > 二师兄:当然用过(废话,C++程序员就没有没用过`std::string`的)。 > 面试官:`std::string("he ......
八股文 八股 string std

C++面试八股文:std::vector和std::list,如何选择?

某日二师兄参加XXX科技公司的C++工程师开发岗位第24面: > 面试官:`list`用过吗? > > 二师兄:嗯,用过。 > > 面试官:请讲一下`list`的实现原理。 > > 二师兄:`std::list`被称为双向链表,和C中手写双向链表本质上没有大的区别。`list`对象中有两个指针,一个 ......
八股文 八股 std vector list

C++面试八股文:std::vector了解吗?

某日二师兄参加XXX科技公司的C++工程师开发岗位第23面: > 面试官:`vector`了解吗? > > 二师兄:嗯,用过。 > > 面试官:那你知道`vector`底层是如何实现的吗? > > 二师兄:`vector`底层使用动态数组来存储元素对象,同时使用`size`和`capacity`记录 ......
八股文 八股 vector std

Leetcode: Arrays.sort() - comparator

Arrays.sort(points,(o1,o2)->{ if(o1[1] == o2[1]) return 0; if(o1[1] < o2[1]) return -1; return 1; }) 根据dp[1]进行升序排列,O(NlogN) ......
comparator Leetcode Arrays sort

Remove Duplicates from Sorted List

Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. **Examp ......
Duplicates Remove Sorted List from

C++17之std::any

一般来说,c++是一种具有类型绑定和类型安全性的语言。值对象声明为具有特定类型,该类型定义哪些操作是可能的以及它们的行为方式。值对象不能改变它们的类型。 std: any是一种值类型,它能够更改其类型,同时仍然具有类型安全性。也就是说,对象可以保存任意类型的值,但是它们知道当前保存的值是哪种类型。在 ......
std any 17

C++ 计时方法 std::chrono

计时的作用:测试某一段代码的运行时间,时间越短,则性能相对越高。 C++11 标准的”最佳计时方法“的代码: 1 #include <chrono> 2 using namespace std; 3 using namespace chrono; 4 5 auto start = system_cl ......
方法 chrono std

C++ std::move 的一些问题

看 SO 上有一个比较奇怪的问题, When does an rvalue reference result in a move vs copy constructor and why? 问题代码: ClassX c = std::move(object_c); // Invokes move co ......
问题 move std

C++ std::chrono的时钟Clock

std::chrono是C++11引入的日期时间处理库,其中包含3种时钟:system_clock,steady_clock,high_resolution_clock。近来需要使用高精度时间,很自然想到使用high_resolution_clock,然而使用后发现并非预期的得到自1970/1/1零 ......
时钟 chrono Clock std

20230407 Arrays.sort

分析以下方法: - Arrays#sort(int[]) - Arrays#sort(Object[] a) ## DualPivotQuicksort - Arrays#sort(int[]) 使用 DualPivotQuicksort - Dual-Pivot Quicksort 是一种快速排序 ......
20230407 Arrays sort

std::thread 六:多线程&单例类

为了避免单例类在多线程中重复的创建,下面提供了两种解决方法: 1.互斥锁+双重检查 2.std::call_once() 方法一:互斥锁+双重检查 #include <iostream> #include <thread> #include <mutex> #include <list> using ......
线程 thread std amp

std::thread 四:异步(async)

*:如果 std::async 中传递参数 std::lunnch::deferred ,就需要等待调用 get() 或者 wait() 才会执行,并且代码非子线程运行,而是在主线程中执行 #include <iostream> #include <thread> #include <mutex> ......
thread async std

std::thread 五:打包任务(packaged_task)

#include <iostream> #include <thread> #include <mutex> #include <list> #include <future> using namespace std; int myThread(int num) { cout << "myThrea ......
packaged_task packaged 任务 thread task

std::thread 三:条件变量(condition_variable())

condition_variable 、 wait 、 notify_one 、 notify_all *:notify_one:通知(唤醒)一个线程 *:notify_all:通知(唤醒)多个线程 #include <iostream> #include <thread> #include <mu ......

std::thread 二:互斥量(带超时的互斥量 timed_mutex())

timed_mutex 、 try_lock_for 、 try_lock_until #include <iostream> #include <thread> #include <mutex> #include <list> using namespace std; class A { publ ......
timed_mutex thread mutex timed std

std::thread 二:互斥量(多个互斥量的解决方法)

// *:这里的lock是函数模板,最少传两个互斥量 // 第一种,使用 lock 和 unlock std::mutex m_mutex1; std::mutex m_mutex2; std::lock(m_mutex1, m_mutex2); m_mutex1.unlock(); m_mutex ......
多个 方法 thread std

std::thread 二:互斥量(lock() & unlock())

mutex 互斥量的作用是保护共享数据 *:有 lock() 就一定要有 unlock() #include <iostream> #include <thread> #include <mutex> #include <list> using namespace std; class A { pu ......
thread unlock lock std amp

std::thread 二:互斥量(lock_guard())

*:使用 lock_guard 后,就不可以使用 lock() 和 unlock() *:lock_guard 和智能指针一样,会自动解锁 #include <iostream> #include <thread> #include <mutex> #include <list> using nam ......
lock_guard thread guard lock std

std::thread 一:创建线程的三种方式

前言: #include <thread> thread.join() // 阻塞 thread.detach() // 非阻塞 thread.joinable() // bool,判断线程是否支持join或者detach 正文: 创建线程有三种方式,分别是:使用函数来创建线程、使用自定义的类来创建 ......
线程 方式 thread std

std::string 拼接字符串

#include <iostream> #include <string> #include <sstream> using namespace std; int main() { string a = "123"; stringstream b; b << 123 << "456" << 789 ......
字符串 字符 string std

C++面试八股文:std::string是如何实现的?

某日二师兄参加XXX科技公司的C++工程师开发岗位第18面: > 面试官:`std::string`用过吧? > > 二师兄:当然用过(废话,C++程序员就没有没用过`std::string`的)。 > > 面试官:`std::string("hello")+"world"`、`"hello"+st ......
八股文 八股 string std

c++多线程 std::async std::future

c++标准库中对线程操作有完善的封装,其中最常用到的如std::thread, std::async。 EffectiveModernCpp中指出,应尽量使用std::async即基于任务的编程而非基于线程的编程。std::thread在前面的文章有提到过,此处仅对std::async作以记录。 正 ......
线程 std future async

CF1830E Bully Sort

[题面传送门](https://www.luogu.com.cn/problem/CF1830E) 我们考虑选中的 $i$,这个位置一定是 $p_i>i$,它想要往后走。而和它交换的 $j$,因为 $\leq i$ 的有 $i$ 个数,现在第 $i$ 个位置已经被 $p_i$ 占据了,所以 $\le ......
1830E Bully 1830 Sort CF