代码如下:
#include<Windows.h>
#include<iostream>
#include<iomanip>
#include<fstream>
#include<Shlwapi.h>
#include<string>
#include<tchar.h>
using namespace std;
int Filetotalnum=0;//总行数
int avgtotalnum = 0;//各函数平均行数
//链表中的数据结构(函数名字,代码行数)
typedef struct Link_data
{
int numline;
char Name[20];
//构造函数必须写上
Link_data() {
numline = 0;
memset(Name,0,sizeof(Name));
}
}Node_data;
//链表节点结构
typedef struct Link_node
{
Node_data data;
struct Link_node *pNext;
}Node;
//创建链表
Node* CreateList(void)
{
Node *pHead = NULL;
//申请的头指针
pHead = (Node *)malloc(sizeof(Node));
//判断是否申请成功
if (NULL == pHead)
{
return NULL;
}
//针对具体结构进行初始化
pHead->data.numline = 0;
memset(pHead->data.Name, 0, 20*sizeof(char));
pHead->pNext = NULL;
return pHead;
}
//为每个函数添加一个节点
Node* Insert2ListTail(Node *pHead, Node_data *pAutoInfo)
{
Node* pNode = NULL;
Node* pNewNode = NULL;
if ((NULL == pHead) || (NULL == pAutoInfo))
{
return NULL;
}
pNode = pHead;
while (pNode->pNext != NULL)
{
pNode = pNode->pNext;
}
pNewNode = (Node *)malloc(sizeof(Node));
if (NULL == pNewNode)
{
return NULL;
}
pNode->pNext = pNewNode;
pNewNode->pNext = NULL;
memcpy(&(pNewNode->data), pAutoInfo, sizeof(Node_data));
return pHead;
}
//删除函数链表
int RemoveList(Node *pHead)
{
Node *pNode = NULL;
Node *pb = NULL;
if (NULL == pHead)
{
return 0;
}
pNode = pHead;
pb = pNode->pNext;
if (NULL == pb)
{
free(pNode);
}
else
{
while (NULL != pb)
{
free(pNode);
pNode = pb;
pb = pb->pNext;
}
free(pNode);
}
pNode = NULL;
return 1;
}
//输出每个函数的代码行数
void outList(Node *pHead)
{
int sumline = 0;
int avgline = 0;
int i = 0;
Node *pNode = NULL;
if (NULL == pHead)
{
return;
}
pNode = pHead->pNext;
while ((NULL != pNode))
{
//printf("\r\n a is %d b is %d", pNode->data.a, pNode->data.b);
sumline = sumline + pNode->data.numline;
i++;
cout << "函数" << i << "行数: "<< pNode->data.numline << endl;
pNode = pNode->pNext;
}
avgline = sumline / i;
avgtotalnum = avgline;
//cout << "函数总个数: " << i<< "占比:" << nHsP << "%" << endl;
cout << "函数平均行数: " << avgline<<endl;
}
//统计函数个数及行数,占比
void FunList(Node *pHead)
{
int sumline = 0;
int avgline = 0;
int i = 0;
Node *pNode = NULL;
if (NULL == pHead)
{
return;
}
pNode = p