我刚刚阅读了算法入门书中的广度优先搜索算法,并在纸上模拟了算法.我现在想做的是在代码中实现它以进行额外的练习.
我正在考虑从头开始实现所有数据结构(邻接列表,"颜色","距离"和"父"数组),但后来我记得当前有图形库,如Boost图库和一些Python中的其他图形API.我也尝试在UVA和Sphere Judge Online上寻找一些与BFS相关的问题,但我不知道哪个问题需要BFS解决方案.
我的问题是什么是最无痛的方法来练习这些图形算法(不仅限于BFS,但在我想实现DFS,Dijkstra,Floyd-Warshall等时也会有用).欢迎有实践问题的网站.
我试图了解C#中的嵌套类.我知道嵌套类是在另一个类中定义的类,我没有得到的是为什么我需要这样做.
我正在用C#编写HTML解析器,并希望包含它在摘要XML块中处理的HTML示例.如何防止<和>字符搞乱Visual Studio 2008的自动文档?
例:
/// <summary>
/// Creates a FlowSegment based on an HTML code, i.e. <bold>
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public FlowSegment(string code)
{
Run Code Online (Sandbox Code Playgroud)
不幸的是,该示例导致此构造函数的工具提示显示(部分):
XML comment includes invalid XML
Run Code Online (Sandbox Code Playgroud)
而不是摘要评论.
如何逃避<和>字符?
我是单元测试的新手,我正在接受一些最佳实践建议.我正在使用Xcode在Cocoa中编码.
我有一个方法可以验证用户输入的URL.我希望它只接受http://协议,只接受具有有效字符的URL.
为此进行一次测试并使用测试数据文件是否可以接受?数据文件提供示例有效/无效URL以及URL是否应该验证.我也用它来检查错误消息的描述和域.
为什么我这样做
我已经用JUnit阅读了Java中的实用单元测试,这给出了一个外部数据文件的例子,这让我觉得这没关系.另外,这意味着我不需要用非常相似的代码编写大量单元测试来测试不同的数据.
但另一方面...
如果我正在测试:
所有在相同的测试数据文件中(因此在同一测试中)这会在以后引起我的问题吗?我读到一个测试应该只是失败的原因之一.
我正在做什么?
如果有的话,其他人如何在单元测试中使用测试数据?
如何在C#中发布以下HTTP请求
POST http://10.0.0.1/st_poe.cgi
Accept: image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Referer: http://10.0.0.1/RST_st_poe.htm
Accept-Language: en-US
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: 10.0.0.1
Content-Length: 21
Connection: Keep-Alive
Pragma: no-cache
Authorization: Basic YWStaW47c3Jsa3NobQ==
ConMethod=++Connect++
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用以下代码.它不起作用.
string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
byte[] bytes = System.Text.Encoding.ASCII.GetBytes("ConMethod=++Connect++");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://10.0.0.1/st_poe.cgi");
request.Method = "POST";
request.Headers.Add("Accept: …Run Code Online (Sandbox Code Playgroud) 我需要重定向没有"www"的任何网址.到"www."的网址 为了更好的搜索引擎优化.我读到mod_rewrite和.htaccess文件可以实现这一点,但我不知道使用正确的代码.有人可以帮忙吗?
在最近玩过Linq(对SQL和对象)以及Microsoft的Entity Framework之后,我想知道non.Net(特别是Java)的等价物是什么?
我怎样才能使我的代码工作?:)我试图制定这个问题,但经过几次失败的尝试后,我认为你们会更快地发现问题,而不是阅读我的"解释".谢谢.
setCtrlState([ memo1, edit1, button1], False);
Run Code Online (Sandbox Code Playgroud)
_
procedure setCtrlState(objs: array of TObject; bState: boolean = True);
var
obj: TObject;
ct: TClass;
begin
for obj in objs do
begin
ct := obj.ClassType;
if (ct = TMemo) or (ct = TEdit) then
ct( obj ).ReadOnly := not bState; // error here :(
if ct = TButton then
ct( obj ).Enabled:= bState; // and here :(
end;
end;
Run Code Online (Sandbox Code Playgroud) 我正在使用Google App Engine环境并使用Python进行编程.我正在创建一个函数,它基本上生成一个随机数字/字母字符串,然后存储到memcache.
def generate_random_string():
# return a random 6-digit long string
def check_and_store_to_memcache():
randomstring = generate_random_string()
#check against memcache
#if ok, then store key value with another value
#if not ok, run generate_random_string() again and check again.
Run Code Online (Sandbox Code Playgroud)
创建两个函数而不是一个大函数会影响性能吗?我更喜欢两个,因为它更符合我的想法,但如果这是"最佳实践",请不要介意将它们结合起来.
for jr in json_reports:
jr['time_created'] = str(jr['time_created'])
Run Code Online (Sandbox Code Playgroud) c# ×3
python ×2
.htaccess ×1
.net ×1
algorithm ×1
apache ×1
cocoa ×1
delphi ×1
function ×1
graph ×1
graph-theory ×1
java ×1
linq ×1
mod-rewrite ×1
nested-class ×1
performance ×1
summary ×1
tobject ×1
unit-testing ×1
xcode ×1
xml ×1