我正在尝试使用Cormen的伪代码实现BST算法但仍存在问题.
这是我的节点代码:
public class Node {
Node left;
Node right;
int value;
Node(int value){
this.value = value;
this.left = null;
this.right = null;
}
}
Run Code Online (Sandbox Code Playgroud)
而对于Bstree:
public class Btree {
Node root;
Btree(){
this.root = null;
}
public static void inorderWalk(Node n){
if(n != null){
inorderWalk(n.left);
System.out.print(n.value + " ");
inorderWalk(n.right);
}
}
public static Node getParent(Btree t, Node n){
Node current = t.root;
Node parent = null;
while(true){
if (current == null)
return null;
if( current.value == n.value ){ …Run Code Online (Sandbox Code Playgroud) 假设我有这样的模型:
class Foo(models.Model):
name = models.CharField("ad",max_length=25)
type = models.ForeignKey(Type)
Run Code Online (Sandbox Code Playgroud)
所以在数据库中我有Foo对象具有相同的名称字段但不同的类型,即:
name type
A 1
A 2
B 1
C 2
A 3
B 3
Run Code Online (Sandbox Code Playgroud)
我将使用这些信息来生成一个html选择表单,显示所有可能的(不同的)名称,所以最后我的选择表单将显示如下:
<select>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
Run Code Online (Sandbox Code Playgroud)
如何获取不同值的列表name?
假设我有这个小模型:
class Deal(models.Model):
purchases = models.IntegerField(default=0)#amount of purchases so far
increase_purchases(self,to_add):
self.update( purchases =self.purchases + to_add)
Run Code Online (Sandbox Code Playgroud)
当我尝试从 shell 使用这个increase_purchases 模型时:
>>> x = Deal.objects.get(id=1)
>>> x.increase_purchases(4)
AttributeError: 'Deal' object has no attribute 'update'
Run Code Online (Sandbox Code Playgroud)
如何为模型编写适当的函数,以便我可以根据需要更新所选的查询购买?
对于我的ecommece网站,我想将部分信用卡号码存储为字符串,为此,我需要加密信息以存储在数据库中,并在用户想要重新使用先前购买的已输入信用卡信息时解密,而无需全部输入再次.
我正在使用Django,因此我需要通过Python解决这个问题.解决这个问题的聪明算法是什么?
我试图理解Django + Jquery和Ajax如何协同工作.
它只是一个简单的/ test/url,它显示了一个输入表单,一旦提交,就会通过ajax从服务器中检索答案.
为此,我写了一个非常小的观点:
def test(request):
if request.is_ajax():
from django.http import HttpResponse
post_text = request.POST.get("post_data")
return HttpResponse("{'response_text': '"+post_text+" recieved.'}", mimetype="application/json")
else:
return render_to_response('test.html', {},context_instance =RequestContext(request))
Run Code Online (Sandbox Code Playgroud)
我已经在urls.py上将此url规则写入我的urlpattern:
(r'^test/$', 'myapp.views.test'),
Run Code Online (Sandbox Code Playgroud)
这是我的test.html模板:
<html>
<head><title>template</title></head>
<script type="text/javascript" src="/media/js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#post_form').submit(function(event){
event.preventDefault(); // cancel the default action
var form = this;
var data = {}
data.post_data = $(form).find('input[@name=our_text]').val();
$.post("/test/",
data,
function(responseData) {
alert(responseData.response_text);
},
"json"
);
});
});
</script>
<body>
<form id="post_form" method="post">
INPUT: <input type="text" name="our_text" />
<input type="submit" …Run Code Online (Sandbox Code Playgroud) 我编写了这段代码,将字符串格式为"0(532)222 22 22"转换为整数,如05322222222.
class Phone():
def __init__(self,input):
self.phone = input
def __str__(self):
return self.phone
#convert to integer.
def to_int(self):
return int((self.phone).replace(" ","").replace("(","").replace(")",""))
test = Phone("0(532) 222 22 22")
print test.to_int()
Run Code Online (Sandbox Code Playgroud)
使用3种替换方法来解决这个问题感觉非常笨拙.我很好奇是否有更好的解决方案?
有这样的清单列表:
data = [['a','x'], ['b','q'], ['c','z']]
search = 'c'
any(e[0] == search for e in data)
Run Code Online (Sandbox Code Playgroud)
这会返回布尔值,但如果我想检索第一个出现的另一对seach变量(换句话说我想在搜索'a'时检索'x'),该怎么办?
我想要仅来自墨西哥的自动完成结果,为此我正在尝试下面的代码并添加边界以确保将墨西哥放在一个矩形中,但是我仍然从国外获得resutlts.
我怎样才能解决这个问题 ?
这是html,相同的代码如下:
<!DOCTYPE html>
<html>
<head>
<title>Google Maps JavaScript API v3 Test: Places Autocomplete</title>
<script src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"
type="text/javascript"></script>
<style type="text/css">
body {
font-family: sans-serif;
font-size: 14px;
}
#map_canvas {
height: 1px;
width: 1px;
display:hidden;
}
#searchTextField{
width:500px;
}
</style>
<script type="text/javascript">
function initialize() {
var options = {
bounds: google.maps.LatLngBounds( google.maps.LatLng(33.1613, -118.4766), google.maps.LatLng(14.3770, -84.8145) )
};
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input, options);
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(autocomplete, 'place_changed', function() {
infowindow.close();
var …Run Code Online (Sandbox Code Playgroud) 我需要修改现有程序,通过写入访问文件来执行一些错误记录,它实际上使用了log4net dll(正如我们通过十六进制编辑器检查dll所发现的)所以在想法中我将需要重新编译调整后的dll与该程序使用的原始.需要非常简单,对于写入访问文件的一些错误,系统应该通过向他发送电子邮件自动警告管理员.
我应该关注项目和文档的哪些部分?作为一个非常新的.net平台以及log4net的人,我很失落.
编辑:似乎嵌入了log4net的配置文件,因此无法直接访问配置.似乎我需要另一种方法来解决这个问题.问候
我计划在文件中存储一组数字,并在需要时读取它.这样做有什么好办法?我可以想到一些方法,例如将每个元素作为文本文件存储在一行中,或者将其序列化并通过该方法存储/调用.速度是我的首要关注点.
谢谢
django ×4
python ×3
java ×2
.net ×1
ajax ×1
algorithm ×1
arrays ×1
binary-tree ×1
credit-card ×1
django-views ×1
encryption ×1
file ×1
google-maps ×1
integer ×1
jquery ×1
list ×1
log4net ×1
logging ×1
string ×1