如何确定我正在使用的当前shell?
ps仅仅命令的输出是否足够?
如何在不同版本的UNIX中完成?
我不确定这些路径是否重复.给定相对路径,如何使用shell脚本确定绝对路径?
例:
relative path: /x/y/../../a/b/z/../c/d
absolute path: /a/b/c/d
Run Code Online (Sandbox Code Playgroud) 我需要找出一个数字是否可以被3整除而不使用%,/或者*.给出的提示是使用atoi()函数.知道怎么做吗?
给定二叉搜索树和整数K,我想找到小于K的最大元素.
在下面的树中,
for K = 13, result = 12
for K = 10, result = 8
for K = 1 (or) 2, result = -1
10
5 12
2 8 11 14
Run Code Online (Sandbox Code Playgroud)
我尝试了以下逻辑.但有没有更好的方法呢?
int findNum(node* node, int K)
{
if(node == NULL)
{
return -1;
}
else if(K <= node->data)
{
return findNum(node->left,K);
}
else if(K > node->data)
{
int t = findNum(node->right,K);
return t > node->data ? t : node->data;
}
return -1;
}
Run Code Online (Sandbox Code Playgroud) 如何确定取幂的前n位数(a b).
eg: for a = 12, b = 13 & n = 4, the first 4 digits are 1069.
Run Code Online (Sandbox Code Playgroud) 在下面的代码段中,
template<typename T1>
void func(T1& t)
{
cout << "all" << endl;
}
template<typename T2>
void func(T2 &t)
{
cout << "float" << endl;
}
// I do not want this
// template<> void func(float &t)
int main()
{
int i; float f;
func(i); // should print "all"
func(f); // should print "float"
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我希望修改模板,通过传递浮动以外的任何类型将打印"all"并传递float将打印"float".我不想要模板特化,而是根据输入类型进行相应的部分特化.我应该怎么做呢.提前致谢.
那个场景,我现在面临的是,我需要定义以下内容,
template<typename T1>
void func(T1 &t)
{
cout << "t1" << endl;
}
template<typename T2>
void func(T2 &t)
{
cout << "t2" << …Run Code Online (Sandbox Code Playgroud) 给定一个二叉搜索树,我需要使用C++中的结构指针将其转换为双向链表(通过以zig zag顺序遍历),如下所示,
鉴于树:
1
|
+-------+---------+
| |
2 3
| |
+----+---+ +----+---+
| | | |
4 5 6 7
| | | |
+--+--+ +--+--+ +--+--+ +--+--+
| | | | | | | |
8 9 10 11 12 13 14 15
Run Code Online (Sandbox Code Playgroud)
节点结构:
struct node
{
char * data;
node * left;
node * right;
};
Run Code Online (Sandbox Code Playgroud)
创建列表(之字形顺序):
1 <-> 3 <-> 2 <-> 4 <-> 5 <-> 6 <-> 7 <-> 15 <-> ... <-> 8 …Run Code Online (Sandbox Code Playgroud) 我试图通过保持下面的空格来颠倒句子中单词的顺序.
[this is my test string] ==> [string test my is this]
Run Code Online (Sandbox Code Playgroud)
我一步一步地做了,
[this is my test string] - input string
[gnirts tset ym si siht] - reverse the whole string - in-place
[string test my is this] - reverse the words of the string - in-place
[string test my is this] - string-2 with spaces rearranged
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以做到这一点?是否也可以在最后一步就地进行?