问题列表 - 第26243页

Objective-C:对包含NSMutableArrays的NSMutableArray进行排序

我目前正在使用NSMutableArrays我的开发来存储从HTTP Servlet获取的一些数据.

一切都很好,因为现在我必须对我的数组中的内容进行排序.

这就是我做的:

NSMutableArray *array = [[NSMutableArray arrayWithObjects:nil] retain];
[array addObject:[NSArray arrayWithObjects: "Label 1", 1, nil]];
[array addObject:[NSArray arrayWithObjects: "Label 2", 4, nil]];
[array addObject:[NSArray arrayWithObjects: "Label 3", 2, nil]];
[array addObject:[NSArray arrayWithObjects: "Label 4", 6, nil]];
[array addObject:[NSArray arrayWithObjects: "Label 5", 0, nil]];
Run Code Online (Sandbox Code Playgroud)

第一列包含Label,第二列是我希望数组按降序排序的分数.

我存储数据的方式是好的吗?有没有更好的办法做到这一点比使用NSMutableArraysNSMutableArray

我是iPhone开发人员的新手,我看过一些关于排序的代码,但对此并不满意.

提前感谢您的回答!

sorting objective-c nsmutablearray

6
推荐指数
2
解决办法
6063
查看次数

用于合并排序的IEnumerable <T>的最有效算法

我有几个巨大的已排序的可枚举序列,我想合并.这些列表被操作为IEnumerable已经排序.由于输入列表已排序,因此应该可以在一次行程中合并它们,而无需重新排序任何内容.

我想保留deferred执行行为.

我试着编写一个天真的算法来做到这一点(见下文).但是,它看起来很丑陋,我确信它可以进行优化.它可能存在更多的学术算法......

IEnumerable<T> MergeOrderedLists<T, TOrder>(IEnumerable<IEnumerable<T>> orderedlists, 
                                            Func<T, TOrder> orderBy)
{
    var enumerators = orderedlists.ToDictionary(l => l.GetEnumerator(), l => default(T));
    IEnumerator<T> tag = null;

    var firstRun = true;
    while (true)
    {
        var toRemove = new List<IEnumerator<T>>();
        var toAdd = new List<KeyValuePair<IEnumerator<T>, T>>();
        foreach (var pair in enumerators.Where(pair => firstRun || tag == pair.Key))
        {
            if (pair.Key.MoveNext())
                toAdd.Add(pair);
            else
                toRemove.Add(pair.Key);
        }

        foreach (var enumerator in toRemove)
            enumerators.Remove(enumerator);

        foreach (var pair in toAdd)
            enumerators[pair.Key] = pair.Key.Current; …
Run Code Online (Sandbox Code Playgroud)

c# linq algorithm optimization performance

35
推荐指数
5
解决办法
6590
查看次数

在部署python时,我们有哪些Web服务器选项?这个过程是否效率低下?

我认为在过去python脚本将运行CGI,这将为每个进程创建一个新线程.

我是新手,所以我不确定,我们有什么选择?

python的web服务器管道是否比php更有效/更低效?

python webserver

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

将静态参数传递给类

据我所知,你无法将参数传递给C#中的静态构造函数.但是,在创建类的实例之前,我确实需要传递2个参数并将它们分配给静态字段.我该怎么办呢?

c# static-constructor static-members

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

以编程方式创建和启动RDP会话(没有gui)

我想知道是否有办法以编程方式在Windows Server上创建和启动远程桌面会话.

我正在尝试创建一个自动工具来创建本地用户,然后启动关联RDP会话.我已经创建了LocalUser并将它们添加到远程桌面用户(使用net.exe).但我对下一步感到震惊:创建并启动用户的rdp-session.如果没有远程桌面客户端Gui,我不知道如何处理这个问题.

我正在使用Windows Server 2003,而我正在使用VS2008和.NET 3.5.

问候.

.net c# c++ windows

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

以编程方式在Java中添加受信任的证书

我使用SSL在用Java编写的两个组件之间进行通信.我不能使用CA,所以我必须自我签名.不幸的是,这意味着当我尝试握手时,我得到一个SunCertPathBuilderException.我可以创建我自己的X509TrustManager,它只信任所有东西,但这种方式违背了签署证书的目的.

我想,在第一次建立连接时,提示用户"使用无效证书进行SSL握手.将证书添加到商店?" 或类似的东西,所以他们可以将它添加到他们的证书商店,就像网页浏览器在无效证书的网站上做的那样.我可以在网上找到很多通过命令行向商店添加证书的例子,但我无法弄清楚如何以编程方式进行.有没有办法做到这一点?

java ssl ssl-certificate

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

将特定字段收集到数组中

根据用户的请求添加具有"行"类的每个div,以便能够一次添加多个项目.所以现在问题是如何将所有表单收集到PHP可以读取的数组中(例如JSON).我猜想已经有一些简单有效的方法吗?

<div class="container">
    <div class="row">
        <input type="text" name="value1" id="textfield" />
        <input type="text" name="value2" id="textfield" />
        <input type="text" name="value3" id="textfield" />
    </div>

</div>
Run Code Online (Sandbox Code Playgroud)

以下是我想通过所示示例实现的内容:

array( 
    array ('value1' => '',
           'value2' => '',
           'value3' => '')
);
Run Code Online (Sandbox Code Playgroud)

谢谢!

更新:表单将使用PHP处理,并且能够在特定的container-div内容上执行类似foreach循环的操作.

php arrays jquery json

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

在PHP中添加格式为H:i的30分钟时间

此刻有一场噩梦,只是看不出为什么它不起作用

我有一个H:i(即10:00,13:30)等形式的值,称为$ time

我想要做的是创建两个新值,$ startTime在$ time之前30分钟,$ endTime在$ time之后30分钟

我尝试过以下但似乎并不想工作

$startTime = date("H:i",strtotime('-30 minutes',$time));
$endTime = date("H:i",strtotime('+30 minutes',$time));
Run Code Online (Sandbox Code Playgroud)

如果我通过10:00作为$ time并且同时回显$ startTime和$ endTime,我得到:

$startTime = 00:30
$startTime = 01:30        
Run Code Online (Sandbox Code Playgroud)

php strtotime

39
推荐指数
3
解决办法
13万
查看次数

邮件"无法继续"AppleScript功能

我正在尝试编写AppleScript以与Mail(在Snow Leopard上)一起使用,以将邮件的图像附件保存到文件夹中.AppleScript的主要部分是:

property ImageExtensionList : {"jpg", "jpeg"}
property PicturesFolder : path to pictures folder as text
property SaveFolderName : "Fetched"
property SaveFolder : PicturesFolder & SaveFolderName

tell application "Mail"
  set theMessages to the selection
  repeat with theMessage in theMessages
    repeat with theAttachment in every mail attachment of theMessage
      set attachmentFileName to theAttachment's name
      if isImageFileName(attachmentFileName) then
        set attachmentPathName to SaveFolder & attachmentFileName
        save theAttachment in getNonexistantFile(attachmentPathName)
      end if        
    end repeat
  end repeat
end tell

on isImageFileName(theFileName)
  set dot to offset …
Run Code Online (Sandbox Code Playgroud)

email applescript

17
推荐指数
2
解决办法
3972
查看次数

创建对象数组C++的问题

我有一个类,我想创建一个数字实例的数组,特别是矩阵类:

class Matrix {    
public:
    Matrix(int sizeX, int sizeY);
    Matrix();
    ~Matrix();
    ....//omiting the rest here
private:
    int dx, dy;
    float **p
    void allocArrays() {
        assert(dx>0);
        assert(dy>0);
        p = new float*[dx];
        for (int i = 0; i < dx; i++){
            p[i] = new float[dy]; 
        }
    }
};
Matrix::Matrix(int sizeX=1, int sizeY=1)
: dx(sizeX),dy(sizeY)  {
    allocArrays();
    for (int i = 0; i < dx; i++)    {
        for (int j = 0; j < dy; j++) {
            p[i][j] = 0;
        }
    }
} …
Run Code Online (Sandbox Code Playgroud)

c++ arrays compiler-errors matrix

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