我试图实施BST,但std::nullptr向我显示错误:
错误:'nullptr'之前的预期unqualified-id
#include <iostream>
#include <memory>
template <typename T>
class BinTreeNode {
public:
BinTreeNode(T key): data {key} {
left = std::nullptr;
right = std::nullptr;
}
~BinTreeNode() {}
T data;
BinTreeNode<T>* left;
BinTreeNode<T>* right;
};
template <typename T>
class BinTree {
public:
BinTree(){
root = std::nullptr;
}
~BinTree() {}
BinTreeNode<T>* root;
};
int main(){
BinTree<int> tree;
}
Run Code Online (Sandbox Code Playgroud)
我试过在谷歌搜索但没有任何有意义的相关内容 std::nullptr
因此,当我需要做一些线性代数时,我更容易将向量看作列向量.因此我更喜欢像(n,1)这样的形状.
形状(n,)和(n,1)之间是否存在显着的内存使用差异?
什么是首选方式?
以及如何将(n,)向量重塑为(n,1)向量.不知怎的,b.reshape((n,1))没有做到这一点.
a = np.random.random((10,1))
b = np.ones((10,))
b.reshape((10,1))
print(a)
print(b)
[[ 0.76336295]
[ 0.71643237]
[ 0.37312894]
[ 0.33668241]
[ 0.55551975]
[ 0.20055153]
[ 0.01636735]
[ 0.5724694 ]
[ 0.96887004]
[ 0.58609882]]
[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
Run Code Online (Sandbox Code Playgroud) #include <iostream>
#include <math.h>
using namespace std;
int main() {
int i{100};
float f{3.14};
double d{3.14159};
cout<<"size of int is: " <<sizeof(i)<<endl;
cout<<"size of float is: " <<sizeof(f)<<endl;
cout<<"size of double is: "<<sizeof(d)<<endl<<endl;;
auto x = sin(3.14159);
cout<<"size of auto that is double is: "<<sizeof(x)<<endl<<endl;
auto y{sin(3.14159)};
cout<<"size of auto that is double is: "<<sizeof(y)<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出是:
int的大小是:4
浮动的大小是:4
双倍的大小是:8
auto的大小是双倍的:8
auto的大小是双倍的:16
为什么是sizeof(y)16?
我正在尝试从Stroustrup的C++ PL4书中做一个练习.任务是:
使用分配这么多的内存
new是bad_alloc被抛出.报告分配了多少内存以及花费了多少时间.这样做两次:一次不写入分配的内存,一次写入每个元素.
以下代码不会引发std::bad_alloc异常.执行程序后,我在终端收到消息"Killed".
也.以下代码在~4秒内退出.但是当我取消注释内存使用消息时
// ++i;
// std::cout << "Allocated " << i*80 << " MB so far\n";
Run Code Online (Sandbox Code Playgroud)
程序将运行几分钟.经过一段时间后,它打印出已经分配了数TB的内存,但我没有看到System Monitor应用程序发生太大变化.这是为什么?
我使用Linux和System Monitor应用程序查看用法.
#include <iostream>
#include <vector>
#include <chrono>
void f()
{
std::vector<int*> vpi {};
int i {};
try{
for(;;){
int* pi = new int[10000];
vpi.push_back(pi);
// ++i;
// std::cout << "Allocated " << i*80 << " MB so far\n";
}
}
catch(std::bad_alloc){
std::cerr << "Memory exhausted\n";
}
}
int main() {
auto t0 …Run Code Online (Sandbox Code Playgroud) 在bash中是否有任何内置功能可以等待许多进程中的1个完成?然后杀死剩余的进程?
pids=""
# Run five concurrent processes
for i in {1..5}; do
( longprocess ) &
# store PID of process
pids+=" $!"
done
if [ "one of them finished" ]; then
kill_rest_of_them;
fi
Run Code Online (Sandbox Code Playgroud)
我正在寻找"其中一个完成"命令.有没有?
#include <iostream>
using namespace std;
class A {
public:
void m1(){ cout << 'A'; }
virtual void m2(){ cout << 'B'; }
virtual void m3(){ cout << 'C'; }
};
class B: public A {
public:
void m1(){ cout << 'D'; }
void m2(){ cout << 'E'; }
};
class C: public B {
public:
void m3(){ cout << 'F'; }
};
int main()
{
cout << "Hello World!" << endl;
A* a = new B();
a->m1();
a->m2();
a->m3();
return …Run Code Online (Sandbox Code Playgroud) 我在pandas dataframe中有一些数据
df['Difference'] = df.Congruent.values - df.Incongruent.values
mean = df.Difference.mean()
std = df.Difference.std(ddof=1)
median = df.Difference.median()
mode = df.Difference.mode()
Run Code Online (Sandbox Code Playgroud)
我想在1个图中绘制直方图和正态分布.是否有一个绘图函数,它将均值和西格玛作为参数?我不在乎它是matplotplib,seaborn还是ggplot.如果我能在1个图中标记数据的模式和中位数,那将是最好的.