c++ - 调试时间问题

标签 c++

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

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/

相关文章:

c++ - 答案怎么是-0?

C++ - 如何调用创建者类/对象

c++ - 如何读取智能卡上的用户数据?

c++ - 与具有重定向 I/O 的子进程通信时出现死锁

c++ - 为什么 (i|o)fstream 使用 const char* 参数作为文件名?

c++ - 混合双重分派(dispatch)和静态多态性

c++ - 我应该为我的项目使用相对包含路径,还是将包含目录放在包含路径上?

c++ - unique_ptr & vector,试图访问已删除的函数,Visual Studio 2013

c++ - 为什么我们在多态性中使用指针?

C++ 错误 3 错误 C2159 : more than one storage class specified