小编mib*_*456的帖子

为什么在链式哈希表中成功搜索的时间复杂度平均为 ?(1+​​(n/m))?

我明白为什么在链式哈希表中搜索不成功的时间复杂度平均为 ?(1+​​(n/m)),因为在不成功搜索中检查的元素的预期数量是 (n/m),并且总数所需时间(包括计算hashFunction(key)的时间)为?(1+(n/m))。但是为什么搜索成功的结果是一样的呢?

algorithm search hashtable time-complexity big-theta

4
推荐指数
1
解决办法
5729
查看次数

在脚本中使用 inotify 监控目录

我写了一个bash脚本来监控一个特定的目录“/root/secondfolder/”,脚本如下:

#!/bin/sh

while inotifywait -mr -e close_write "/root/secondfolder/"
do
    echo "close_write"
done
Run Code Online (Sandbox Code Playgroud)

当我在“/root/secondfolder/”中创建一个名为“fourth.txt”的文件并向其中写入内容,保存并关闭它时,它输出以下内容但不回显“close_write”:

/root/secondfolder/ CLOSE_WRITE,CLOSE fourth.txt
Run Code Online (Sandbox Code Playgroud)

有人可以指出我正确的方向吗?

linux bash monitoring echo inotifywait

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

试图从文件中获取特定行.程序跳过行.(PHP)

我有一个小问题.我需要使用PHP从文本文件中获取一行.以下是文本文件的示例:

你好2010-10-25
你好2010-10-26
你好2010-10-27
你好2010-10-28
你好2010-10-29
你好2010-10-30
你好2010-10-31

我拿出包含"2010-10-26"的行的代码是这样的:

<?php
 $datefile = fopen('file.txt', 'r') or exit("Unable to open file.txt");

 while(!feof($datefile))
 {
  $date = "2010-10-26";
  $string = fgets($datefile);
  if(strpos($string, $date)==true)
  {
   echo fgets($datefile);
  }

 }
 fclose($datefile);
?>
Run Code Online (Sandbox Code Playgroud)

它没有打印出"hello 2010-10-26"这一行,而是打印出"你好2010-10-27"我不知道最新情况,请帮忙.

php file-io

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

递归地反转C中的数组

这是我的代码的一部分,我试图以递归方式反转字符串:

    char reverse[10];
    gets(reverse);
    reverseString(reverse, (strlen(reverse) - 1));
    void reverseString(char ar[], int n)
    {
        if (n == 0)
        {
            return;
        }
        else
        {
            int temp = ar[n];
            ar[n] = *(ar);
            *(ar) = temp;
            reverseString((ar + 1), (n - 1));
        }
    }
Run Code Online (Sandbox Code Playgroud)

当我输入字符串"hello"时,它将字符串更改为"ohell".我需要它将字符串完全反转为"olleh".有人可以帮忙吗?

c string algorithm recursion reverse

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