2015-10-05 134 views
-2

我是新算法中的時間複雜性。 這是計算文本文件中字數的代碼。 我的問題是,每次我的程序打印一個話多的文件中的實際計數,就像如果我在我的文件11個字它打印12這個程序的時間複雜度是多少?

#include<fstream> 
#include<iostream> 
#include<string> 
using namespace std; 
/* main function */ 
void main() 
{ 
    ifstream inFile; //file file name 
    string fileName; 
     string word; 
     int count = 0; 
     inFile.open("example.txt"); 
     while(!inFile.eof()) 
      { 
      inFile >> word; 
        ++count; 
       } 
    cout << "Number of words in file is " << count<<endl; 
inFile.close(); 

} 
//this file is for counting the number of words in a text file** 

回答

相關問題