我正在努力了解Functors的工作原理,所以我在这里阅读:http://learnyouahaskell.com/making-our-own-types-and-typeclasses#the-functor-typeclass
我有一个函数,它采用一个映射并计算值的总和(这是一个列表).
reduce :: Map String [Int] -> Map String Int
reduce = fmap sum
Run Code Online (Sandbox Code Playgroud)
我真的不明白它是如何fmap
工作的所以我读了它并试图制作我自己的版本.我无法真正测试它,因为Map已在Haskell库中定义.
这是对的吗?
instance Functor (Map k) where
fmap f fromList[] = []
fmap f fromList[(k, v): xs] = (f v) fmap xs
Run Code Online (Sandbox Code Playgroud) 这段代码是什么意思?
if( item.compareTo(root.element) < 0 ){
}
Run Code Online (Sandbox Code Playgroud)
我读到了:
"按字典顺序比较两个字符串.返回一个整数,指示此字符串是否大于(结果> 0),等于(结果是= 0)或小于(结果是<0)参数."
但我不明白.有人可以用一个例子解释一下吗?
我想将像"我的狗"这样的字符串分成以下数组:
| M | y | space char will be in here | D | o | g |
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
String []in_array;
input = sc.next();
in_array = input.split(""); //Note this there is no delimiter
for(int k=1; k < in_array.length; k++){
System.out.print(" "+in_array[k]);
}
Run Code Online (Sandbox Code Playgroud)
编辑:
它只打印出"我的"
有没有办法将二进制转换为排序数组而不必遍历每个数组索引的树?
Node root;
Node runner;
int current_smallest;
void findsmallest(Node root){
//Pre-order traversal
if(root == null){
return;
}else{
runner = root;
if(current_smallest == null){
current_smallest = runner.element;
}else{
if(current_smallest > runner.element){
current_smallest = runner.element;
}
}
findsmallest(runner.left);
findsmallest(runner.right);
}
}
void fill_array( int [] array ){
for(int i =0; i < array.length(); i++){
findsmallest(root);
array[i] = current_smallest;
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,如果树中有很多节点,则可能需要很长时间.顺便说一句,我忘了显示整个树必须在开始时遍历以获得数组的长度.
我正在尝试制作一种public void limit()
检查速率限制的方法,并且如果速率受限,则会在重置之前长时间休眠.但是,我无法弄清楚如何制作RateLimitStatus.我试过了:
RateLimitStatus status = twitter.getRateLimitStatus();
但实际上并没有返回RateLimitStatus ......坦白说,我不确定这是什么意思.无论如何,如果有人知道如何获得RateLimitStatus,他们的帮助将非常感激,因为目前我的项目由于速率限制而能够崩溃,我想改变它.提前致谢!
我该怎么说呢:
while(input is not an int){
do this
}
Run Code Online (Sandbox Code Playgroud)
我试过这段代码,但我知道这是错的:
int identificationnumber;
Scanner sc3 = new Scanner(System.in);
identificationnumber = sc3.nextInt();
while( identificationnumber != int){ // this line is wrong
Scanner sc4 = new Scanner(System.in);
identificationnumber = sc4.nextInt();
}
Run Code Online (Sandbox Code Playgroud)
请任何建议.谢谢.
我试图通过使用它来比较两个2D阵列.但我一直得到" 阵列不一样. "即使它们是相同的.
int i;
int j = 0;
int k;
int l;
List<Integer> list = new ArrayList<Integer>();
List<Integer> list1 = new ArrayList<Integer>();
List<Integer> zero = new ArrayList<Integer>();
for ( i = 1; i <= 16; i++) {
list.add(i);
}
//System.out.println(list); //[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
Collections.shuffle(list.subList(1, 15));
System.out.println(list);
Collections.replaceAll(list, 16, 0);
System.out.println(list);
// System.out.println(list); //[11, 5, 10, 9, 7, 0, 6, 1, 3, 14, 2, 4, 15, 13, …
Run Code Online (Sandbox Code Playgroud) 我的主要问题是矢量如何工作.
我知道链表是连接在一起的节点列表.这就是我在脑海中想象的方式.但我无法想象矢量是什么样的.
我读到矢量具有随机访问权限,就像数组一样.但什么是随机访问?计算机最终是否最终在内部搜索索引?我这样说是因为我可以通过运行for循环来重载[]
运算符以给出链表中的第 i 个元素.
什么是阵列?我知道数组是如何工作的,但它背后的是什么,它是一个节点集合吗?我只是为了一般知识而要求这个.
这是关于向量的问题.它看起来与用于链表的函数非常相似.
如果我安装了Netbeans,如何使用Notepad ++运行程序?我不想使用IDE,所以我可以更好地编程.