信息实际上并未存储在节点数组中

Information not actually being stored inside array of nodes

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 行告诉我我的逻辑没有问题,因为它应该在我的链表数组中插入节点。但它实际上并没有将它们添加到链表数组中。

    //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;
  }

您正在按值而不是引用传递指针,因此传入变量指向的地址没有改变。

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