我需要找到两个函数执行相同操作但用不同算法编写的时间.我需要找到两者中最快的
这是我的代码片段
Stopwatch sw = new Stopwatch();
sw.Start();
Console.WriteLine(sample.palindrome()); // algorithm 1
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);//tried sw.elapsed and sw.elapsedticks
sw.Reset(); //tried with and without reset
sw.Start();
Console.WriteLine(sample.isPalindrome()); //algorithm 2
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
Run Code Online (Sandbox Code Playgroud)
从技术上讲,这应该给两个算法花费的时间.这使得算法2更快.但是如果我交换两个函数的调用,它会给出不同的时间.就像我先调用algorithm2而第二次调用algorithm1一样,它表示algorithm1更快.
我不知道我做错了什么.
我正在使用ant编译器编译.java文件.我收到以下错误"包org.apache.commons.io不存在错误"
我下载了apache Commons IO二进制文件并将.jar文件粘贴到"C:\ Program Files\Java\jdk1.7.0_51\lib\missioncontrol\plugins"中
任何帮助.我是否需要修改build xml文件的类路径?
<target name="compile" description="Compile source code">
<mkdir dir="${build.dir}/classes"/>
<javac includeantruntime="false"
srcdir="src"
destdir="${build.dir}/classes"
classpathref="classpath"
encoding="UTF8"
debug="on"
deprecation="on">
<include name="**/*.java"/>
<exclude name="**/NutchExample.java"/>
</javac>
<copy todir="${build.dir}/classes/lia/tools">
<fileset dir="src/lia/tools" excludes="**/*.java"/>
</copy>
</target>
Run Code Online (Sandbox Code Playgroud) 我在编写这个相当简单的程序时遇到了麻烦.我有两个A类和B类.B有一个A的对象.我需要编写B的Copy构造函数,这样B的两个实例将具有不同的A实例.有没有任何巧妙的方法来做到这一点?要做的一件事是获取parm的所有成员变量,创建一个新的A对象并分配这些成员变量.但是如果类有更多的成员变量,那么这是一个问题.如何以简单的方式写这个?
class A
{
public:
int data;
A()
{
}
A(int parm) : data(parm)
{
}
A(const A&parm)
{
this->data = parm.data;
}
A& operator = (const A& parm)
{
if (this != &parm)
{
this->data = parm.data;
}
return *this;
}
~A()
{
cout << "A is destroyed";
}
};
class B
{
public:
A *a;
B()
{
a = new A(10);
}
B(const B&parm)
{
// How to copy the value of parm so this and parm have …Run Code Online (Sandbox Code Playgroud) int main()
{
int a = 10;
const int &b = a;
int &c = b; //gives error : C should a reference to a const b
auto d = b; // why const is ignored here?
d = 15;
cout << a << d;
}
Run Code Online (Sandbox Code Playgroud)
在c ++ Primer中,提到“ 引用类型中的const总是低级的 ”,那么为什么auto d = b不是恒定的呢?
这是我的C程序:
#include<stdio.h>
main()
{
int a,b;
int pow (int,int);
printf("Enter the values of a and b");
scanf("%d %d",&a,&b);
printf("Value of ab is %d",pow(a,b));
}
pow(int c,int d)
{
return c*d;
}
Run Code Online (Sandbox Code Playgroud)
我的程序中没有包含math.h.我正在使用gcc编译器.我收到以下错误
ex22.c:在函数`main'中:
ex22.c:6:错误:`pow'的冲突类型
搜索后我发现math.h中有一个pow函数.但我不包括math.h但我仍然得到错误.怎么样 ?
我能够删除MyTasks,并My workflow从dashlet如何把它从标题中删除?我通过编辑从dashlet中删除了my-tasks.get.html.ftl.但是如何从标题菜单中删除.我应该修改哪个文件.我正在使用4.2e社区版
考虑一下该计划
#include<stdio.h>
int main()
{
char a[] = "hello";
printf("%c", *(a + 5));
printf("%c", *(a + 6));
printf("%c", *(a + 99));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这里第一个printf是打印NULL还是垃圾值?最后两个printf怎么样?
我很困惑因为我在数组绑定之外访问.