小编Gil*_*il'的帖子

Ocaml列表到树

我想编写一个函数load: 'a option list -> 'a tree,它从给定列表中恢复二进制树,其中包含后缀顺序的元素.如果列表不代表任何树,则您的函数应该引发异常Load(您必须先声明它).

树被定义为:

type ‘a btree = L of ‘a | N of ‘a btree * ‘a btree
Run Code Online (Sandbox Code Playgroud)

到目前为止,我所做的是:

exception Load ;;

let rec load l =
    match l with
        | [] -> raise Load
        | Some x::_ -> L x
        | None::t -> N(?,load t)
;; 
Run Code Online (Sandbox Code Playgroud)

以下是输入列表的示例:

[Some 2; Some 0; None; Some 5; Some 9; Some 20; None; None; None]
Run Code Online (Sandbox Code Playgroud)

如何做到这一点真是太棘手了.由于列表是后缀顺序,我想知道是否更好地使用List.foldright函数??

tree ocaml list tree-traversal

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

jQuery数组和Foreach

这是我的数组,我需要做一个foreach来显示每个图像等.基本上数组包含幻灯片和幻灯片信息,我需要输入一个包含信息的div(如果我知道如何访问它,我可以这样做).

var slides = new Array();
slides[1] = {slidetitle: 'title 1',
             slidetext: 'text 1',
             image1: '',
             magnifyposit: '',
             buttontext: 'button text 1',
             buttonurl: 'http://www.google.com'};
slides[2] = {slidetitle: 'title 2',
             slidetext: 'text 2',
             image1: '',
             magnifyposit: '',
             buttontext: 'button text 2',
             buttonurl: 'http://www.google.com'};
slides[3] = {slidetitle: 'title 3',
             slidetext: 'text 3',
             image1: '',
             magnifyposit: '',
             buttontext: 'button text 3',
             buttonurl: ''};
slides[4] = {slidetitle: 'title 4',
             slidetext: 'text 4',
             image1: '',
             magnifyposit: '',
             buttontext: 'button text 4',
             buttonurl: 'http://www.google.com'};
slides[5] = …
Run Code Online (Sandbox Code Playgroud)

html css jquery

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

列表范围的类型:如何使我的函数更少多态?

我有一个功能

sasiad (x,y) = [ (x+dx,y+dy) | dy <- [-1..1], dx <- [-1..1], x+dx >= 0, y+dy >= 0]
Run Code Online (Sandbox Code Playgroud)

我不喜欢那种功能的类型.我希望它返回[(Int,Int)]而不是[(t,t1)] 强制ghci可以做到吗?

polymorphism haskell typing ghci

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

struts2中的密码标记无法正常工作

我是struts2的新手.我用jsp等领域username,password,email,postal code像这样.我在输入jsp中使用了 <s:password>tag password字段.在提交页面时,如果该页面中有任何错误,则将操作重定向到相同的输入页面.在这种情况下,password字段被清除,其他字段在那里输入值,但我想显示password先前输入的值而不是空值的字段.怎么样?

struts2

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

更改标签值

任何线索,我怎么能访问每个thclass="CenteredHeader"通过jQuery添加更多的参数a标签?

<tr class="CenteredHeader">
  <th scope="col"></th>
  <th scope="col">
      <a href="/BoxOffice/Movies/807?sort=MovieName&amp;sortdir=ASC">Pelicula</a>
  </th>
  <th scope="col">
      <a href="/BoxOffice/Movies/807?sort=TechnologyName&amp;sortdir=DESC">Tecnologia</a>
  </th>
</tr>
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

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

在Java中查找字符串中的最小单词

我正在尝试在用户输入的字符串中找到最小的单词.这是我到目前为止:

import java.util.*;
public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    String myText = sc.next();
    String[] myWords = myText.split(" ");
    int shortestLength,shortestLocation;

    shortestLength=(myWords[0]).length();

    shortestLocation=0;

    for (int i=1;i<myWords.length;i++) {
        if ((myWords[i]).length() < shortestLength) {
            shortestLength=(myWords[i]).length();
            shortestLocation=i;
        }
    }
    System.out.println(myWords[shortestLocation]);
}
Run Code Online (Sandbox Code Playgroud)

如果我输入"SMALLEST WORD SHOULD BE A",输出应该是,A但它只是给我字符串的第一个单词.有任何想法吗?

java string

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

如何在多个进程中同时生成随机数?

如何在C中生成随机数,以便在同一时间运行多个进程?

我想用srandrand,但我不知道如何(也许使用进程ID?).

c random

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

如何用Java发送POST请求?

当我从JSP发送请求时,我使用此代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form method="post"  action="http://translate.intelsoft.az" id="tform" name="ftext">
<input class="gogo1"  value="a" name="l" id="l1" /> <div class="il">
<p>Rusca</p>
<textarea class="ilkin1" name="t" id="t1" >
???????????????????
???????????????????
???????????????????
???????????????????</textarea>
<div><input class="gogo" type="submit" value="T?rcüm?1" name="b1" /></div></div>    </form>

</body>
</html> 
Run Code Online (Sandbox Code Playgroud)

并且响应是正确的,以便我看到参数的值.但是当我从Java发送时,我没有得到正确的答复.我认为参数没有正确发送.这是我的Java代码:

String urlParameters = "t=???????????????????&l=a";
String request = "http://translate.intelsoft.az";
URL url = null;
try {
    url = new URL(request);
} catch (MalformedURLException …
Run Code Online (Sandbox Code Playgroud)

java jsp httprequest

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

sizeof(array)在此strstr重新实现中未提供预期值

我已经将这个简单的strstr重新制作作为练习,但是有一个我不理解的错误

#include <iostream>
#include "windows.h"

using namespace std;

int strstr2(char *arr, char *findme)
{
    const int sizearr = sizeof(arr) / sizeof(char);
    const int sizefindme = sizeof(findme) / sizeof(char);

    int j=0;
    for(int i=0; i<sizearr; i++)
    {
        if(arr[i] == findme[j])
        {
            // Match
            if(j == sizefindme-1)
                return i;
            else
                j++;
        }
        else
        {
            j = 0;
        }
    }
    return -1;
}


int main (int argc, char **argv) 
{
    char arr[] = "I'd like 2% milk";
    char toBeFound[] = "like";

    int …
Run Code Online (Sandbox Code Playgroud)

c++ arrays pointers sizeof

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

指派中的指针解除引用

当教授说这ptr=&x表示一个变量ptr分配变量的地址时,我正在观看讲座并感到困惑 x.并且因为y=*ptr+1*ptr表示存储在x(或值x)的值.我在这里稍微感到困惑,因为*ptr应该指向x正确的地址,而不是存储在的值x?有人可以再详细说明一下吗?

c pointers variable-assignment

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