问题列表 - 第41527页

C#Listbox设置所选项目

我有一个带有值的C#列表框

Profile 1
Profile 2
Profile 3
Run Code Online (Sandbox Code Playgroud)

我想在表单加载时选择配置文件2.我该怎么做呢?

c# listbox selected listboxitem winforms

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

将选择侦听器添加到GXT Grid?

我正在尝试向我的GXT(Ext GWT)Grid添加一个选择监听器,但我似乎无法解决它.我尝试了很多变化而没有运气:

myGrid.addListener(Events.Select, new SelectionListener<ComponentEvent>() {

     @Override
     public void componentSelected(ComponentEvent ce) {
         System.out.println("selected");
     }
});
Run Code Online (Sandbox Code Playgroud)

java grid gwt gxt

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

哈希:内部如何运作?

这听起来可能是一个非常模糊的问题,但事实并非如此.我在维基上经历过Hash函数描述,但理解它并不是很有帮助.

我正在寻找像Hashing这样相当复杂的主题的简单答案.这是我的问题:

  1. 哈希是什么意思?它在内部如何运作?
  2. 它遵循什么算法?
  3. 有什么区别HashMap,HashTableHashList
  4. "恒定时间复杂度"是什么意思?为什么哈希的不同实现会给出恒定的时间操作?
  5. 最后,为什么大多数的面试问题HashLinkedList询问,有没有从测试受访者的知识,为任何特定的逻辑?

我知道我的问题清单很大但我真的很感激,如果我能够对这些问题得到一些明确的答案,因为我真的想了解这个主题.

java algorithm hash data-structures

50
推荐指数
4
解决办法
7万
查看次数

用A*来解决旅行推销员

我的任务是编写A*算法的实现(提供启发式算法),以解决旅行商问题.我理解算法,它很简单,但我只是看不到实现它的代码.我的意思是,我明白了.节点的优先级队列,按距离+启发式(节点)排序,将最近的节点添加到路径上.问题是,如果无法从前一个最近的节点到达最近的节点会发生什么?如何将"图形"作为函数参数?我只是无法看到算法实际上如何运作,如代码.

我在发布问题之前阅读了维基百科页面.反复.它并没有真正回答问题 - 搜索图表的方式与解决TSP的方式不同.例如,您可以构造一个图形,其中任何给定时间的最短节点总是导致回溯,因为相同长度的两条路径不相等,而如果您只是尝试从A到B,那么两条路径长度相同的是相同的.

您可以通过始终最接近的方式派生一个图形,通过该图形永远不会到达某些节点.

我真的不知道A*如何适用于TSP.我的意思是,找到从A到B的路线,当然,我明白了.但TSP?我没有看到连接.

algorithm a-star traveling-salesman

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

如何在QtJambi中获取stdin,stdout,stderr文本流的QIODevice实例?

我想获得QIODevice一个代表标准IO流(stdin,stdout,stderr在QtJambi),这样我可以得到通知,每当一个新行可以读取或写入.

java io qt qt-jambi

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

查找字符串中最长的重复子字符串需要Java函数吗?

需要java函数来查找字符串中最长的重复子串

For instance, if the input is “banana”,output should be "ana" and we have count the number of times it has appeared in this case it is 2.

解决方法如下

public class Test{
public static void main(String[] args){
System.out.println(findLongestSubstring("i like ike"));
System.out.println(findLongestSubstring("女士,我是亚当"));
System.out.println(findLongestSubstring("当生活递给你柠檬水时,做柠檬"));
System.out.println(findLongestSubstring("banana"));
}

public static String findLongestSubstring(String value) {
    String[] strings = new String[value.length()];
    String longestSub = "";

    //strip off a character, add new string to array
    for(int i = 0; i < value.length(); i++){
        strings[i] = new String(value.substring(i)); …
Run Code Online (Sandbox Code Playgroud)

java algorithm

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

按键分组并对值求和

我有一系列哈希:

[{"Vegetable"=>10}, {"Vegetable"=>5}, {"Dry Goods"=>3>}, {"Dry Goods"=>2}]
Run Code Online (Sandbox Code Playgroud)

我需要在inject这里使用,但我确实在苦苦挣扎.

我想要一个反映前一个哈希重复键总和的新哈希:

[{"Vegetable"=>15}, {"Dry Goods"=>5}]
Run Code Online (Sandbox Code Playgroud)

我控制输出此哈希的代码,以便我可以在必要时进行修改.结果主要是哈希,因为这可能会最终嵌套任意数量的级别,然后很容易在数组上调用flatten但不会平滑哈希的键/值:

def recipe_pl(parent_percentage=nil)
  ingredients.collect do |i|

    recipe_total = i.recipe.recipeable.total_cost 
    recipe_percentage = i.ingredient_cost / recipe_total

    if i.ingredientable.is_a?(Purchaseitem)
      if parent_percentage.nil?
        {i.ingredientable.plclass => recipe_percentage}
      else
        sub_percentage = recipe_percentage * parent_percentage
        {i.ingredientable.plclass => sub_percentage}
      end
    else
      i.ingredientable.recipe_pl(recipe_percentage)
    end
  end
end 
Run Code Online (Sandbox Code Playgroud)

ruby hash key enumerable

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

每个GROUP BY表达式必须至少包含一个不是外部引用的列

我在这做错了什么?我收到此错误:

SELECT LEFT(SUBSTRING(batchinfo.datapath, PATINDEX('%[0-9][0-9][0-9]%', batchinfo.datapath), 8000), 
            PATINDEX('%[^0-9]%', SUBSTRING(batchinfo.datapath, PATINDEX('%[0-9][0-9][0-9]%', 
            batchinfo.datapath), 8000))-1),
            qvalues.name,
            qvalues.compound,
            qvalues.rid
FROM batchinfo JOIN qvalues ON batchinfo.rowid=qvalues.rowid
WHERE LEN(datapath)>4
GROUP BY 1,2,3
HAVING rid!=MAX(rid)
Run Code Online (Sandbox Code Playgroud)

我想按第一列,第二列和第三列进行分组.

没有团体和没有,它工作正常.

t-sql sql-server

30
推荐指数
3
解决办法
14万
查看次数

如何以线程安全的方式将控制台程序的输出重定向到文本框?

我无法将控制台输出重定向到Windows窗体文本框.问题与线程有关.我正在以下列方式运行控制台应用程序,

private void RunConsoleApp()
{
    Process proc = new Process();
    proc.StartInfo.FileName = "app.exe";
    proc.StartInfo.Arguments = "-a -b -c";
    proc.StartInfo.UseShellExecute = false;

    // set up output redirection
    proc.StartInfo.RedirectStandardOutput = true;
    proc.StartInfo.RedirectStandardError = true;    
    proc.EnableRaisingEvents = true;
    proc.StartInfo.CreateNoWindow = true;

    // Set the data received handlers
    proc.ErrorDataReceived += proc_DataReceived;
    proc.OutputDataReceived += proc_DataReceived;

    proc.Start();
    proc.BeginErrorReadLine();
    proc.BeginOutputReadLine();
    proc.WaitForExit();

    if (proc.ExitCode == 0)
    {
        out_txtbx.AppendText("Success." + Environment.NewLine);
    }
    else
    {
        out_txtbx.AppendText("Failed." + Environment.NewLine);
    }
}
Run Code Online (Sandbox Code Playgroud)

然后使用此输出处理程序捕获和处理数据,

// Handle the date received by the console process …
Run Code Online (Sandbox Code Playgroud)

c# multithreading textbox console-application winforms

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

在UITableView单元格中格式化日期和时间

我需要格式化日期和时间tableView:cellForRowAtIndexPath:.由于创建NSDateFormatter一个相当繁重的操作,我已经使它们变得静态.这是以行为单位格式化日期和时间的最佳方法吗?

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    MyCell*cell = (MyCell*)[self.tableView
                                dequeueReusableCellWithIdentifier:CellIdentifier
                                                     forIndexPath:indexPath];

    static NSDateFormatter *dateFormatter = nil;
    if (!dateFormatter)
    {
       dateFormatter = [[NSDateFormatter alloc] init];
       [dateFormatter setLocale:[NSLocale currentLocale]];
       [dateFormatter setDateStyle:NSDateFormatterLongStyle];
    }
    cell.dateLabel = [dateFormatter stringFromDate:note.timestamp];


     static NSDateFormatter *timeFormatter = nil;
     if (!timeFormatter)
     {
        timeFormatter = [[NSDateFormatter alloc] init];
        [timeFormatter setTimeStyle:NSDateFormatterShortStyle];
      }    
      cell.timeLabel = [timeFormatter stringFromDate:note.timestamp];

return cell;
}
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c nsdateformatter ios

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