我想计算这段代码的时间复杂度? [英] I want to calculate the time complexity for this code ?

查看:64
本文介绍了我想计算这段代码的时间复杂度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  private   int 计数( string  dir, string  [] mask)
{
countblanklin = 0 ;

countcommentlines = 0 ;
this .statusBar.Text = dir;
this .statusBar.Update();

int totalCount = 0 ;
string [] dirs = Directory.GetDirectories(dir);


string dirName = dir.Substring( this .startPath 。长度);
foreach 字符串模式 in 掩码)
{
string [] filenames = Directory.GetFiles(dir,pattern);
foreach 字符串文件 in filenames)
{
if (!running)
return 0 ;

int count = CountFile(file);
if (count > 0
{
string name = Path.GetFileName(file);
TreeNode node = new TreeNode(name + + count + );
node.ImageIndex = 1 ;
node.SelectedImageIndex = 1 ;
listBox1.Items.Add(node);
totalCount + = count;

FileEntry entry = new FileEntry(name,dirName,count);
this .files.Add(entry);
}
}
}
return totalCount;
}

private int CountFile( string path)
{
int count = 0 < /跨度>;
countblanklin = 0 ;
countcommentlines = 0 ;
countifs = 0 ;
countelse = 0 ;
StatementCoverage = 0 ;
Brain b = new Brain();
尝试
{
StreamReader reader = new StreamReader(路径) ;
String s;
do
{
s = reader.ReadLine();
if (s!= null
{
count ++;
bool a = b.IsSource(s);

if (b.CountIfs)countifs ++;
if ((b._isinsideif || b._isinsideelse)&&(s.Trim()。StartsWith( @ })|| s.Trim()。StartsWith( @ else)))b ._isinsideif = false ;
if ((b._isinsideif || b._isinsideelse)&&(s.Trim()。StartsWith( @ })))b ._isinsideelse = false ;
if ((b._isinsideif || b._isinsideelse)&&!((s.Trim()。StartsWith( @ if))||(s.Trim()。StartsWith( @ else))))
StatementCoverage ++;


if (b.CountElae)countelse ++;
if (b.CountMultiLineComments)
countcommentlines ++;
}
} while (s!= null );
reader.Close();
}
catch (IOException)
{
}

return count;
}
_____________________________________________
private void cmdCount_Click( object sender,System.EventArgs e)
{

DateTime then = DateTime.Now;
System.Diagnostics.Process.GetCurrentProcess()。ProcessorAffinity =(System。 IntPtr 1 ;
TimeSpan diff = DateTime.Now - then;
}
字符串 .Format( {0:00}:{1:00}:{2:00}。{3:00},(diff.Hours),diff.Minutes,diff.Sec





我尝试过:



试图找到在线工具计算时间复杂度,但无法找到任何,

任何人都可以帮我找工具

或手动计算

解决方案

短语我想计算......与找我工具和或为我计算位不兼容。

我们不是不在这里为你做你的工作。

如果你想让别人为你做你的工作,你必须付钱 - 我建议你去Freelancer.com并在那里问。



但请注意:你得到你所支付的费用。支付花生,买猴子。



另外,亲自试一试,并且看看你能走多远。如果你遇到一个特定的问题,那么问这个问题。但是这里的任何人都没有坐下来为yoU计算代码的时间复杂度!


我会在这里使用.NET类StopWatch你可以找到你需要的任何东西

Classe Stopwatch(System.Diagnostics) [ ^ ]

private int Count(string dir, string[] mask)
{
countblanklin=0;

countcommentlines = 0;
this.statusBar.Text = dir;
this.statusBar.Update();

int totalCount = 0;
string[] dirs = Directory.GetDirectories(dir);


string dirName = dir.Substring(this.startPath.Length);
foreach (string pattern in mask)
{
string[] filenames = Directory.GetFiles(dir, pattern);
foreach (string file in filenames)
{
if (!running)
return 0;

int count = CountFile(file);
if (count > 0)
{
string name = Path.GetFileName(file);
TreeNode node = new TreeNode(name + " (" + count +")");
node.ImageIndex = 1;
node.SelectedImageIndex = 1;
listBox1.Items.Add(node);
totalCount += count;

FileEntry entry = new FileEntry(name, dirName, count);
this.files.Add(entry);
}
}
}
return totalCount;
}

private int CountFile(string path)
{
int count = 0;
countblanklin=0;
countcommentlines=0;
countifs=0;
countelse=0;
StatementCoverage = 0;
Brain b = new Brain();
try
{
StreamReader reader = new StreamReader(path);
String s;
do
{
s = reader.ReadLine();
if (s != null)
{
count++;
bool a = b.IsSource(s);

if (b.CountIfs) countifs++;
if ((b._isinsideif || b._isinsideelse) && (s.Trim().StartsWith(@"}") || s.Trim().StartsWith(@"else"))) b._isinsideif = false;
if ((b._isinsideif || b._isinsideelse) && (s.Trim().StartsWith(@"}"))) b._isinsideelse = false;
if ((b._isinsideif || b._isinsideelse) && !((s.Trim().StartsWith(@"if")) || (s.Trim().StartsWith(@"else"))))
StatementCoverage++;


if (b.CountElae) countelse++;
if (b.CountMultiLineComments)
countcommentlines++;
}
} while (s != null);
reader.Close();
}
catch (IOException)
{
}

return count;
}
_____________________________________________
private void cmdCount_Click(object sender, System.EventArgs e)
{

DateTime then = DateTime.Now;
System.Diagnostics.Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)1;
TimeSpan diff = DateTime.Now - then;
} 
String.Format("{0:00}:{1:00}:{2:00}.{3:00}", (diff.Hours), diff.Minutes, diff.Sec



What I have tried:

tried to find online tools that calculate the time complexity but couldnt find any ,
can anyone help me finding a tool
or calculate it manually

解决方案

The phrase "I want to calculate..." does not work well with the "find me a tool" and "or calculate it for me" bits.
We are not not here to do your work for you.
If you want someone to do your job for you, you have to pay - I suggest you go to Freelancer.com and ask there.

But be aware: you get what you pay for. Pay peanuts, get monkeys.

Alternatively, give it a try yourself, and see how far you get. If you meet a specific problem, then ask about that. But nobody here is going to sit down and work out the time complexity of code for yoU!


I would use .NET class StopWatch here you can find anything you need
Classe Stopwatch (System.Diagnostics)[^]


这篇关于我想计算这段代码的时间复杂度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆