我有一个家庭作业,我必须建设性地和破坏性地反转一个数组列表,并为不同长度的列表计时。我的 Arraylist 每次运行时都会更新,但它似乎没有在这些方法中注册,因为我没有得到我的计时值并且似乎找不到我的错误。
到目前为止,我的代码如下。
public ArrayList ConstructiveReverseDeveloped()
{
ArrayList Temp = new ArrayList();
for (int i = Developed.Count - 1; i >= 0; i--)
{
Apps cur = (Apps)Developed[i];
Temp.Add(cur);
}
return Temp;
}
public void TimingConstructive()
{
DateTime startTime;
TimeSpan endTime;
startTime = DateTime.Now;
ConstructiveReverseDeveloped();
endTime = DateTime.Now.Subtract(startTime);
Console.WriteLine("---------------------------------------------------------");
Console.WriteLine("Time taken for Constructive Reverse of Developed : {0}", endTime);
}
public void DestructiveReverseDeveloped()
{
//ArrayList x = cloneDeveloped();
for (int i = Developed.Count - 1; i >= 0; i--)
{
Apps cur = (Apps)Developed[i];
Developed.RemoveAt(i);
Developed.Add(cur);
}
}
public void TimingDestructive()
{
DateTime startTime;
TimeSpan endTime;
startTime = DateTime.Now;
DestructiveReverseDeveloped();
endTime = DateTime.Now.Subtract(startTime);
Console.WriteLine("Time taken for Destructive Reverse of Developed : {0}",endTime.ToString());
Console.WriteLine("---------------------------------------------------------");
}
你们能否指出我为什么没有得到计时值的正确方向?我不想要确切的答案,而只是帮助理解。
谢谢