我需要将焦点设置为当前元素的下一个元素(在其他情况下是立即上一个).
例如:
<li>item1</li> <- prev element (get this element)
<li>item1</li><- current element
<li>item1</li> <- next element (get this element)
<li>item1</li>
Run Code Online (Sandbox Code Playgroud)
这是我用的
var curr = (event.target).next();
$(curr).trigger('focus');
Run Code Online (Sandbox Code Playgroud)
当我检查currfirebug中的值时,由于某种原因显示未定义.
我正试图在我的光线跟踪器中遍历3D KD树.树是正确的,但我的遍历算法似乎有问题,因为与使用强力方法相比,我遇到了一些错误(一些小的表面区域似乎被忽略).
注意:所讨论的光线都不与任何轴平行.
这是我的遍历算法:
IntersectionData* intersectKDTree(const Ray &ray, KDTreeNode* node, double tMin, double tMax) const{
if (node->GetObjectCount()==0) return 0;
IntersectionData* current = 0;
bool intersected = false;
if (node->m_isLeaf){
...test all primitives in the leaf...
}
else{
int axis = node->m_splitAxis;
double splitPos = node->m_splitPos;
double tSplit = (splitPos-ray.point[axis])/ray.direction[axis];
KDTreeNode* nearNode = ray.point[axis]<splitPos?node->m_leftnode:node->m_rightnode;
KDTreeNode* farNode = ray.point[axis]<splitPos?node->m_rightnode:node->m_leftnode;
if (tSplit > tMax)
return intersectKDTree(ray, nearNode , tMin, tMax);//case A
else if (tSplit < tMin){
if(tSplit>0)
return intersectKDTree(ray, farNode, tMin, tMax);//case B …Run Code Online (Sandbox Code Playgroud) 是否有可能以foreach相反的顺序遍历Collections对象的语句?
如果不是foreach声明,还有另一种方式吗?
如何在没有C(无C++)递归的情况下有效地遍历树的每个节点?
假设我有该树的以下节点结构:
struct Node
{
struct Node* next; /* sibling node linked list */
struct Node* parent; /* parent of current node */
struct Node* child; /* first child node */
}
Run Code Online (Sandbox Code Playgroud)
Nodestruct 的成员来存储其他信息.我有这个可以排序的列表.在排序完成后,如何将带有.neutral的li项目移动到列表的末尾?
$(".thumbs").sortable({
stop: function(event, ui) {
// move .neutral at the end of this list
}
});
<ul class="thumbs">
<li>red</li>
<li>green</li>
<li class="neutral">none</li>
<li>yellow</li>
<li>blue</li>
<ul>
Run Code Online (Sandbox Code Playgroud) 所以我一直在研究实现最低共同的祖先算法.我查看了许多不同的算法(主要是Trajan解决方案的变体或RMQ的变体).
我使用的是非二叉树.我的树通常会在查询之间进行更改,因此预处理不一定是值得的.树不应超过50-75个节点.我想知道的是我是否应该使用他们的算法或只是坚持自己的算法.
我的算法
myLCA(node1, node2) {
parentNode := [ ]
while (node1!=NULL) {
parentNode.push(node1)
node1 := node1.parent
}
while (node2!=NULL) {
for i in parentNode.size {
if (parentNode(i) == node2) {
return node2;
}
}
node2 := node2.parent
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个数组有1 2 3 4 5值.
array a = [ 1 , 2, 3, 4, 5]
Run Code Online (Sandbox Code Playgroud)
现在我想以循环方式遍历它.我喜欢打印2 3 4 5 1或3 4 5 1 2或5 1 2 3 4等等.任何算法对此有何看法?
编辑:我想以循环方式打印所有组合.我不想在初始阶段说出起点.
以下代码有点神秘.在非玩具版本的问题中,我试图在monad Result中进行monadic计算,其值只能在IO中构造.似乎IO背后的魔力使这样的计算严格,但我无法弄清楚究竟是怎么发生的.
代码:
data Result a = Result a | Failure deriving (Show)
instance Functor Result where
fmap f (Result a) = Result (f a)
fmap f Failure = Failure
instance Applicative Result where
pure = return
(<*>) = ap
instance Monad Result where
return = Result
Result a >>= f = f a
Failure >>= _ = Failure
compute :: Int -> Result Int
compute 3 = Failure
compute x = traceShow x $ Result x
compute2 :: Monad …Run Code Online (Sandbox Code Playgroud) 我试图从N树数据结构返回一个小部件列表.在我的单元测试中,如果我有大约2000个小部件,每个小部件都有一个依赖,我会遇到堆栈溢出.我认为正在发生的是for循环导致我的树遍历不是尾递归.什么是在scala中写这个的更好方法?这是我的功能:
protected def getWidgetTree(key: String) : ListBuffer[Widget] = {
def traverseTree(accumulator: ListBuffer[Widget], current: Widget) : ListBuffer[Widget] = {
accumulator.append(current)
if (!current.hasDependencies) {
accumulator
} else {
for (dependencyKey <- current.dependencies) {
if (accumulator.findIndexOf(_.name == dependencyKey) == -1) {
traverseTree(accumulator, getWidget(dependencyKey))
}
}
accumulator
}
}
traverseTree(ListBuffer[Widget](), getWidget(key))
}
Run Code Online (Sandbox Code Playgroud) 在一次采访中,我获得了一个功能:
f(n)= square(f(n-1)) - square(f(n-2)); for n>2
f(1) = 1;
f(2) = 2;
Here n is the level of an n-array tree. f(n)=1,2,3,5,16...
Run Code Online (Sandbox Code Playgroud)
对于n给定N-Array的每个级别,我必须在每个级别打印f(n)节点.例如:
At level 1 print node number 1 (i.e. root)
At level 2 print node number 2 (from left)
At level 3 print node number 3 (from left)
At level 4 print node number 5... and so on
Run Code Online (Sandbox Code Playgroud)
如果number of nodes(say nl)在任何级别n的less than f(n),则必须打印node number nl%f(n) …