C语言求翻译。

#include<iostream>
#include<fstream>
#include<malloc.h>
#include<stdlib.h>
const int ERROR=0;
using namespace std;
struct LinkHash
{
LinkHash *next;
int m_nValue;
int count;
};
struct _Data
{
int Value;
int Count;
};
char *file[101]=
{};
class CHashTable
{
private:
LinkHash *HashTable[101];
public:
CHashTable();
~CHashTable();
void HashCollision(int data);
void WriteToFile();
_Data GetMaxFreq(char *filename);
};
CHashTable::CHashTable()
{

int i;
for(i=0;i<100;i++)
{
HashTable[i]=(LinkHash*)malloc(sizeof(LinkHash));
if(!HashTable[i])
exit(ERROR);
HashTable[i]->count=0;
HashTable[i]->next=NULL;
HashTable[i]->m_nValue=-1;
}
}
CHashTable::~CHashTable()
{
}
int HashFunc(int key)
{
return key%100;
}
void CHashTable::HashCollision(int data)
{
LinkHash *newNode;
LinkHash *head;
newNode=(LinkHash*)malloc(sizeof(LinkHash));
if(!newNode)
exit(ERROR);
newNode->next=NULL;
newNode->m_nValue=data;
newNode->count=0;
int p;
bool isRep=false;
p=HashFunc(data);
head=HashTable[p];
while(head->next)
{
head=head->next;
if(head->m_nValue==data)
{
head->count++;
isRep=true;
break;
}

}
if(isRep==false)
{
head->next=newNode;
head=newNode;
head->count++;
}

}
void CHashTable::WriteToFile()
{
int i;
ofstream fout;
for(i=0;i<100;i++)
{
LinkHash *p;
fout.open(file[i]);
if(HashTable[i]->next)
{
p=HashTable[i]->next;
while(p)
{
fout<<p->m_nValue<<" "<<p->count<<endl;
p=p->next;
}
}
fout.close();
fout.clear();
}
}
求每一句程序的作用。

这是C++
#include<iostream>
#include<fstream>
#include<malloc.h>
#include<stdlib.h>
//-------------------------上面的是调用头文件
const int ERROR=0; //全局变量
using namespace std;
struct LinkHash
{
LinkHash *next;
int m_nValue;
int count;
};//结构体
struct _Data
{
int Value;
int Count;
};//结构体
char *file[101]={};//全局变量

class CHashTable //ç±»
{
private:
LinkHash *HashTable[101];
public:
CHashTable();
~CHashTable();
void HashCollision(int data);
void WriteToFile();
_Data GetMaxFreq(char *filename);
};
CHashTable::CHashTable()//应该是构造函数
{
int i;
for(i=0;i<100;i++)
{
HashTable[i]=(LinkHash*)malloc(sizeof(LinkHash));
if(!HashTable[i])
exit(ERROR);
HashTable[i]->count=0;
HashTable[i]->next=NULL;
HashTable[i]->m_nValue=-1;
}
}
CHashTable::~CHashTable()//析够函数
{
}
int HashFunc(int key)//自定义函数
{
return key%100;
}
void CHashTable::HashCollision(int data)//自定义函数
{
LinkHash *newNode;
LinkHash *head;
newNode=(LinkHash*)malloc(sizeof(LinkHash));
if(!newNode)
exit(ERROR);
newNode->next=NULL;
newNode->m_nValue=data;
newNode->count=0;
int p;
bool isRep=false;
p=HashFunc(data);
head=HashTable[p];
while(head->next)
{
head=head->next;
if(head->m_nValue==data)
{
head->count++;
isRep=true;
break;
}

}
if(isRep==false)
{
head->next=newNode;
head=newNode;
head->count++;
}

}
void CHashTable::WriteToFile()//自定义函数
{
int i;
ofstream fout;
for(i=0;i<100;i++)
{
LinkHash *p;
fout.open(file[i]);
if(HashTable[i]->next)
{
p=HashTable[i]->next;
while(p)
{
fout<<p->m_nValue<<" "<<p->count<<endl;
p=p->next;
}
}
fout.close();
fout.clear();
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-07-09
这是C++,你如果学的是C语言的话,建议找C语言的。
第2个回答  2015-07-09
楼主需要每句都翻译吗

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网