代码之家  ›  专栏  ›  技术社区  ›  Zachary Collins

未实际存储在节点阵列中的信息

  •  0
  • Zachary Collins  · 技术社区  · 7 年前
    node* nodeArray[1000]; 
    for (int j = 0; j < 1000; j++){
    nodeArray[j] = new node;
    }
    int nodeCounter = 0;
    string temporary = "";
    string cont; //file content
    int i = 0;
    while (getline(fileObject, cont)){
      for (int k = 0; k < cont.length(); k++) 
        cont[k] = tolower(cont[k]);
      while (i < cont.length()){ 
    

        //cout << "nodeArray [" << nodeCounter << "] : " << temporary << "\n";
        insert(nodeArray[nodeCounter], temporary);
        temporary = "";
      i++;
    }
    i = 0;
    nodeCounter++;
    
    }
    

    这是我的插入函数,它可能会干扰程序

      void insertion(node* tail, string info){
          node* temp = new node;
          temp->data = info;
          temp->previous = tail;
          temp->next = NULL;
          tail = temp;
      }
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   adisib    7 年前

    您是按值传递指针,而不是按引用传递,因此传入的变量所指向的地址不会更改。

    改变 void insertion(node* tail, string info){ 进入 void insertion(node*& tail, string info){