小编jos*_*osh的帖子

如何确定我正在使用的当前shell?

如何确定我正在使用的当前shell?

ps仅仅命令的输出是否足够?

如何在不同版本的UNIX中完成?

unix bash shell csh tcsh

587
推荐指数
14
解决办法
46万
查看次数

C中%n格式说明符的用途是什么?

%nC 中的格式说明符有什么用?有人可以用一个例子来解释吗?

c printf

116
推荐指数
7
解决办法
10万
查看次数

将相对路径转换为绝对路径?

我不确定这些路径是否重复.给定相对路径,如何使用shell脚本确定绝对路径?

例:

relative path: /x/y/../../a/b/z/../c/d

absolute path: /a/b/c/d
Run Code Online (Sandbox Code Playgroud)

unix shell perl path absolute-path

56
推荐指数
4
解决办法
5万
查看次数

检查一个数字是否可以被3整除

我需要找出一个数字是否可以被3整除而不使用%,/或者*.给出的提示是使用atoi()函数.知道怎么做吗?

division modulo integer-division

37
推荐指数
8
解决办法
2万
查看次数

在BST中找到小于K的最大元素

给定二叉搜索树和整数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)

c c++ binary-search-tree

18
推荐指数
2
解决办法
8260
查看次数

取幂的前n位数

如何确定取幂的前n位数(a b).

eg: for a = 12, b = 13 & n = 4, the first 4 digits are 1069.
Run Code Online (Sandbox Code Playgroud)

c c++ math exponentiation

8
推荐指数
3
解决办法
2728
查看次数

功能模板的部分特化

在下面的代码段中,

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++ templates template-specialization function-templates

8
推荐指数
3
解决办法
7156
查看次数

如何将二进制搜索树转换为双向链表?

给定一个二叉搜索树,我需要使用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)

c++ linked-list data-structures

7
推荐指数
1
解决办法
6292
查看次数

C++中的字符串反转

我试图通过保持下面的空格来颠倒句子中单词的顺序.

[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)

有没有其他方法可以做到这一点?是否也可以在最后一步就地进行?

c c++ string

7
推荐指数
1
解决办法
2446
查看次数

流运算符重载

为什么要将流操作符(<<,>>)的重载保存为朋友而不是让它们成为类的成员?

c++ operator-overloading

6
推荐指数
1
解决办法
1670
查看次数