问题列表 - 第27246页

JavaScript BubbleSort,如何提高其效率?

拥有与此类似的Bubblesort例程。我需要通过在对数组排序或对数组进行排序时停止循环来提高效率。

function sortNumbers(listbox) {
  var x, y, holder;
  // The Bubble Sort method.
  for(x = 0; x < ranarray.length; x++) {
    for(y = 0; y < (ranarray.length-1); y++) {
      if(ranarray[y] > ranarray[y+1]) {
        holder = ranarray[y+1];
        ranarray[y+1] = ranarray[y];
        ranarray[y] = holder;
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

javascript bubble-sort

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

使用HtmlAgilityPack仅选择特定DIV中的项目

我正在尝试使用HtmlAgilityPack从包含在div中的页面中提取所有链接,<div class='content'>但是,当我使用下面的代码时,我只需在整个页面上获取所有链接.这对我来说真的没有意义,因为我从之前选择的子节点调用SelectNodes(在调试器中查看时只显示来自该特定div的HTML).所以,每当我调用SelectNodes时,它就会回到根节点.我使用的代码如下:

HtmlWeb hw = new HtmlWeb();
HtmlDocument doc = hw.Load(@"http://example.com");
HtmlNode node = doc.DocumentNode.SelectSingleNode("//div[@class='content']");
foreach(HtmlNode link in node.SelectNodes("//a[@href]"))
{
    Console.WriteLine(link.Value);
}
Run Code Online (Sandbox Code Playgroud)

这是预期的行为吗?如果是这样,我如何让它做我期待的事情?

c# html-agility-pack

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

如何在OPENGL中旋转或翻译单个对象实例?

让我们说我有一个四个立方体的场景.我怎么说在OpenGL中只旋转/翻译其中两个立方体而不用glrotatef和gltranslate改变其他立方体?我不想定义自己的同质坐标.

opengl

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

Python 2.5中的urllib或urllib2是否支持https?

我在这里先向您的帮助表示感谢.我很困惑,相同的代码适用于python 2.6但不适用于2.5.这是代码

import cgi, urllib, urlparse, urllib2
url='https://graph.facebook.com'

req=urllib2.Request(url=url)
p=urllib2.urlopen(req)
response = cgi.parse_qs(p.read())
Run Code Online (Sandbox Code Playgroud)

这是我得到的例外

Traceback (most recent call last):
  File "t2.py", line 6, in <module>
    p=urllib2.urlopen(req)
  File "/home/userx/lib/python2.5/urllib2.py", line 124, in urlopen
    return _opener.open(url, data)
  File "/home/userx/lib/python2.5/urllib2.py", line 381, in open
    response = self._open(req, data)
  File "/home/userx/lib/python2.5/urllib2.py", line 404, in _open
    'unknown_open', req)
  File "/home/userx/lib/python2.5/urllib2.py", line 360, in _call_chain
    result = func(*args)
  File "/home/userx/lib/python2.5/urllib2.py", line 1140, in unknown_open
    raise URLError('unknown url type: %s' % type)
urllib2.URLError: <urlopen error unknown url …
Run Code Online (Sandbox Code Playgroud)

python https urllib urllib2 python-2.5

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

使用jQuery将元素样式设置为:hover样式

是否可以(使用jQuery或其他方式)将某个元素的:hover样式设置为样式表中定义的样式?

.regStyle {
   background-color: #000;
}

.regStyle:hover {
   background-color: #fff;
} 

Trying it out

$("#differentButton").click(function(){
    // this doesn't work 
    $("#someElement").addClass("regStyle:hover").remove("regStyle");
});
Run Code Online (Sandbox Code Playgroud)

css jquery

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

从数组中选择第i个最小元素

我有一个分而治之的方法来从数组中找到第i个最小的元素.这是代码:

public class rand_select{
    public static int Rand_partition(int a[], int p, int q, int i) {
        //smallest in a[p..q]
        if ( p==q) return a[p];
        int r=partition (a,p,q);
        int k=r-p+1;
        if (i==k) return a[r];
        if (i<k){
            return Rand_partition(a,p,r-1,i);
        }
        return Rand_partition(a,r-1,q,i-k);
    }

    public static void main(String[] args) {
        int a[]=new int []{6,10,13,15,8,3,2,12};
        System.out.println(Rand_partition(a,0,a.length-1,7));
    }

    public static  int partition(int a[],int p,int q) {
        int  m=a[0];
        while (p < q) {
            while (p < q && a[p++] < m) {
                p++;
            }
            while …
Run Code Online (Sandbox Code Playgroud)

java algorithm

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

复合主要和基数

我对复合主键和列的基数有一些疑问.我在网上搜索,但没有找到任何确定的答案,所以我再试一次.问题是:

上下文:大(50M - 500M行)OLAP Prep表,而不是NOSQL,而不是Columnar.MySQL和DB2

1)PK中的键的顺序是否重要?

2)如果列的基数变化很大,应首先使用.例如,如果我有CLIENT/CAMPAIGN/PROGRAM,其中CLIENT是高度主要的,CAMPAIGN是适中的,PROGRAM几乎就像一个位图索引,什么顺序是最好的?

3)如果有Where子句且没有Where子句(对于视图),Join的最佳顺序是什么

提前致谢.

mysql database indexing modeling

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

在bash中检查命令行标志的正确方法

在脚本中间,我想检查命令行上是否传递了给定的标志.以下是我想要的,但看起来很难看:

if echo $* | grep -e "--flag" -q
then
  echo ">>>> Running with flag"
else
  echo ">>>> Running without flag"
fi
Run Code Online (Sandbox Code Playgroud)

有没有更好的办法?

注:我明确地希望列出一个开关/ getopt的所有标志.(在这种情况下,任何这样的东西都会变成完整脚本的一半或更多.而且if的主体也只是设置了一组变量)

bash flags command-line

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

IUnityContainer.Resolve <T>抛出错误声称它不能与类型参数一起使用

昨天我已经实现了代码:

CustomerProductManager productsManager = container.Resolve<CustomerProductManager>();
Run Code Online (Sandbox Code Playgroud)

它是可编辑和工作的.

今天(可能是我修改了一些东西)我经常收到错误:

非泛型方法'Microsoft.Practices.Unity.IUnityContainer.Resolve(System.Type,string,params Microsoft.Practices.Unity.ResolverOverride [])'不能与类型参数一起使用

我的同事有相同的源代码,没有相同的错误.为什么?如何解决问题?

PS

行"使用Microsoft.Practices.Unity;" 存在于使用部分.

我试图用非泛型版替换泛型版:

CustomerProductManager productsManager = (CustomerProductManager)container.Resolve(typeof(CustomerProductManager));
Run Code Online (Sandbox Code Playgroud)

并得到另一个错误:

方法'Resolve'没有重载需要'1'参数

It seems like one of the assemblies is not referenced.. but which one? I have 2 of them referenced: 1. Microsoft.Practices.Unity.dll 2. Microsoft.Practices.ServiceLocation.dll

P.P.S. I've saw similar problem http://unity.codeplex.com/WorkItem/View.aspx?WorkItemId=8205 but it is resolved as "not a bug"

Any thought will be helpful

.net c# generics compilation unity-container

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

Use cases for NoSQL

NoSQL最近在我们的行业中受到了很多关注.我真正感兴趣的是关于人们对关系数据库存储使用的最佳用例的看法.什么应该引发开发人员认为特定数据集更适合NoSQL解决方案.我对MongoDBCouchDB特别感兴趣,因为他们似乎在PHP开发方面获得了最多的报道,这是我的重点.

sql couchdb relational-database mongodb nosql

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