我正在寻找支持以下操作的功能数据结构:
正常的功能链表仅支持O(n)附加,而我可以使用普通LL然后反转它,反向操作也是O(n),它(部分地)否定O(1)cons操作.
我想做一个迭代来计算给定公式的所有可能性.我需要写下嵌套迭代,但无法做到正确.我不擅长算法:(
为了计算所有可能性(%0-%100)3个常数{z1,z2,z3}值,我准备:
a=frange(0,1.0,0.01)
for z1 in a:
for z2 in a:
for z3 in a:
calculate(z1,z2,z3)
Run Code Online (Sandbox Code Playgroud)
并按照我的预期正常工作.
如果z是一个由n个值组成的列表(在我的例子中n可以是2-30),你建议我使用哪种算法来处理这个问题?如何创建嵌套迭代?
我正在尝试将pickerView添加到我的表视图中的一行,但在执行此操作后,我看到的只是单元格内的黑色矩形.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
pickerView = [[[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 0.0, 200, 300)] autorelease];
[cell.contentView addSubview:pickerView];
}
}
Run Code Online (Sandbox Code Playgroud)
我真的不知道如何解决这个问题.有人可以帮帮我吗?
我有一个透明的png图像"foo.png",我打开了另一个图像
im = Image.open("foo2.png");
Run Code Online (Sandbox Code Playgroud)
现在我需要的是将foo.png与foo2.png合并.
(foo.png包含一些文本,我想在foo2.png上打印该文本)
Perl对默认值非常好:
: jmglov@laurana; perl -e '@foo; printf "%d\n", $foo[123]'
0
: jmglov@laurana; perl -e '%foo; printf "%d\n", $foo{bar}'
0
Run Code Online (Sandbox Code Playgroud)
Ruby可以做同样的事情,至少对于哈希来说:
>> foo = Hash.new(0)
=> {}
>> foo[:bar]
=> 0
Run Code Online (Sandbox Code Playgroud)
但是这些似乎对数组不起作用:
>> foo = Array.new(0)
=> []
>> foo[123]
=> nil
>> foo[124] = 0
=> 0
>> foo[456] = 0
=> 0
>> foo[455,456]
=> [nil, 0]
Run Code Online (Sandbox Code Playgroud)
是否可以为数组提供默认值,因此当它们自动扩展时,它们会被填充为0而不是nil?
当然,我可以解决这个问题,但要付出代价:
>> foo[457,458] = 890, 321
=> [890, 321]
>> foo[456] += 789
NoMethodError: You have a nil object when you …Run Code Online (Sandbox Code Playgroud) 以下是编程scala第1章的引用:
闭包是一种强大的抽象,对象系统和基本控制结构通常使用它们来实现
显然这个声明并不是专门针对Scala而是关闭Closures,但我对它没有多大意义.也许它是一些智慧的珍珠,仅适用于那些强大的编译器作者!
那么谁使用Closures实现基本控制结构?为什么?
编辑:我记得读一些有关自定义控制结构中常规"使用的盖,方法调用的最后一个参数"语法和使用元类或提供的结构,你的代码use的关键字与分类.它可能是相关的吗?
编辑:我发现语法常规定制控制结构的下列参考这里(滑块38):
定制控制结构
感谢关闭
- 当闭包是最后一个时,它们可以被放在
围绕参数 的括号中unless(account.balance > 100.euros, { account.debit 100.euros })unless(account.balance > 100.euros) { account.debit 100.euros }- 签名
def unless(boolean b, Closure c)
显然,groovy提供的是一种语法糖,用于使基于Closure的自定义控制结构看起来像语言本身提供的一流控制结构.
#include <iostream>
int main()
{
const int i=10;
int *p =(int *) &i;
*p = 5;
cout<<&i<<" "<<p<<"\n";
cout<<i<<" "<<*p;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
0x22ff44 0x22ff44
10 5
请解释.
我从数据库中获取数据并显示GridView罚款.但是我需要在每个显示的文本下方放置一个单独的按钮.当我点击按钮时,我必须做一些事情.在这里,我使用自定义列表适配器从DB中检索数据.我怎么能这样做?
我的代码:
public class HomePage extends Activity {
private ArrayList<SingleElementDetails> allElementDetails=new ArrayList<SingleElementDetails>();
DBAdapter db=new DBAdapter(this);
String category, description;
String data;
String data1;
GridView gridview;
Button menu;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.homepage);
menu=(Button)findViewById(R.id.menus);
menu.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
gridview=(GridView)findViewById(R.id.gridview);
allElementDetails.clear();
db.open();
long id;
//id=db1.insertTitle1(category, description,r_photo);
Cursor cursor = db.getAllTitles1();
while (cursor.moveToNext())
{
SingleElementDetails single=new SingleElementDetails();
single.setCateogry(cursor.getString(1));
single.setDescription(cursor.getString(2));
single.setImage(cursor.getBlob(3));
allElementDetails.add(single);
}
db.close();
CustomListAdapter adapter=new CustomListAdapter(HomePage.this,allElementDetails);
gridview.setAdapter(adapter);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
我的customListAdapter:
import java.io.ByteArrayInputStream;
import java.util.ArrayList; …Run Code Online (Sandbox Code Playgroud) 我有一些代码可以获得.MP3文件的标题
def getTitle(fileName):
print "getTitle"
audio = MP3(fileName)
try:
sTitle = str(audio["TIT2"])
except KeyError:
sTitle = os.path.basename(fileName)
sTitle = replace_all(sTitle) #remove special chars
return sTitle
Run Code Online (Sandbox Code Playgroud)
我会用这个函数调用
sTitle = getTitle("SomeSong.mp3")
Run Code Online (Sandbox Code Playgroud)
为了解决另一个问题,我想在自己的线程上生成它,所以我改变了我的调用
threadTitle = Thread(target=getTitle("SomeSong.mp3"))
threadTitle.start()
Run Code Online (Sandbox Code Playgroud)
这正确地调用了函数并解决了我的其他问题,但现在我无法弄清楚如何将sTitle的返回值从函数转换为Main.
python ×3
algorithm ×1
android ×1
arrays ×1
c++ ×1
c++11 ×1
closures ×1
f# ×1
gridview ×1
groovy ×1
image ×1
java ×1
objective-c ×1
onclick ×1
ruby ×1
scala ×1
uipickerview ×1
uitableview ×1
visual-c++ ×1
xcode ×1