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()){
Here is where the problem comes in. The cout line tells me that my logic is fine in that it should be inserting nodes inside my array of linkedlists. But it's not actually adding them to the array of linkedlist.
这就是问题所在.cout行告诉我,我的逻辑很好,因为它应该在我的链表列表中插入节点。但它实际上并没有将它们添加到链表的数组中。
//cout << "nodeArray [" << nodeCounter << "] : " << temporary << "\n";
insert(nodeArray[nodeCounter], temporary);
temporary = "";
i++;
}
i = 0;
nodeCounter++;
}
And here's my insert function that might be messing with the program
这是我的插入功能,可能会搞乱该程序
void insertion(node* tail, string info){
node* temp = new node;
temp->data = info;
temp->previous = tail;
temp->next = NULL;
tail = temp;
}
1 个解决方案
#1
2
You are passing a pointer by value, rather than reference, so the address the passed-in variable is pointing to is not changed.
您是按值传递指针而不是引用,因此传入变量指向的地址不会更改。
Change void insertion(node* tail, string info){
into void insertion(node*& tail, string info){
.
更改void插入(node * tail,string info){into void insertion(node *&tail,string info){。
#1
2
You are passing a pointer by value, rather than reference, so the address the passed-in variable is pointing to is not changed.
您是按值传递指针而不是引用,因此传入变量指向的地址不会更改。
Change void insertion(node* tail, string info){
into void insertion(node*& tail, string info){
.
更改void插入(node * tail,string info){into void insertion(node *&tail,string info){。