小编Bra*_*den的帖子

O(log n)算法在排序数组中找到最佳插入位置

我正在尝试制作一个算法,找到将目标插入已排序数组的最佳位置.

目标是返回项目的位置(如果它存在于列表中),否则返回它将保持列表排序的位置.

所以说我有一个清单:

   0   1   2   3   4    5    6
 ---------------------------------
 | 1 | 2 | 4 | 9 | 10 | 39 | 100 |
 ---------------------------------
Run Code Online (Sandbox Code Playgroud)

而我的目标项是14 它应该返回索引位置5

伪代码我目前有:

array = generateSomeArrayOfOrderedNumbers()

number findBestIndex(target, start, end)
    mid = abs(end - start) / 2

    if (mid < 2) 
        // Not really sure what to put here
        return start + 1 // ??

    if (target < array[mid])
        // The target belongs on the left side of our …
Run Code Online (Sandbox Code Playgroud)

arrays sorting algorithm linked-list

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

具有管理员权限的Directory.SetCurrentDirectory.

我正在尝试设置一个工作流助手,需要从几个不同的映射网络驱动器中获取文件/执行命令.

我有3个单独的映射驱动器.Z:\ Y:\和W:\(以及我的C:\)

当我尝试按照以下方式做某事时:

    Directory.SetCurrentDirectory("Z:\\xampp\\htdocs");

    Console.WriteLine(Environment.CurrentDirectory);
    Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)

它工作得很好.它将Z:\xampp\htdocs按照应有的方式输出.
但是,如果我再次运行完全相同的代码但具有管理员权限,它会给我一个System.IO.DirectoryNotFoundException例外.

c# .net-4.5

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

标签 统计

.net-4.5 ×1

algorithm ×1

arrays ×1

c# ×1

linked-list ×1

sorting ×1