gpt4 book ai didi

c++ - 调试时间问题

转载 作者:太空宇宙 更新时间:2023-11-04 13:09:44 24 4
gpt4 key购买 nike

我创建了一个数据包结构。我阅读文件的文本并转换为字典顺序。为此,我必须将两个字符串转换为小写字母以进行比较(一个用于当前节点,一个用于它旁边的节点)。但我的问题是当我有大文本文件时,它必须为我插入的每个节点不断地将字符串转换为小写,有时需要很长时间才能处理。我想知道是否有任何更好的方法来调整它,以便我可以增加性能时间。

void insert(string v)
{
if(head == NULL){ //empty list
head = new BagNode;
head->dataValue = v;
//head->dataCount = 0;
head->next = NULL;

}
else
{
BagNode * n = new BagNode; // new node
n->dataValue = v;
BagNode * current = head; //for traversal
//current = head;
n->dataCount = 0;
if(!isBefore(current->dataValue, v)) //new head
{
n->next = head;
head = n;
}
else{ //mid and tail insert
while(current->next && isBefore(current->next->dataValue,v))
{
current = current->next;
}
n->next = current->next;
current->next = n;

}
}
}

比较两个节点

 bool isBefore(string a, string b) 
{
transform(a.begin(), a.end(), a.begin(), ::tolower);
transform(b.begin(), b.end(), b.begin(), ::tolower);
if(a == b) {
return true;
}
else {
return false;
}
}

最佳答案

使用 g++ 或 gcc 调试 C 或 C++ 程序

1) gcc/g++ -g myprogram.c/myprogram.cpp

结果会是a.out

2) gdb a.out

希望对你有帮助!

关于c++ - 调试时间问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40479560/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com