【发布时间】:2015-05-25 05:45:35
【问题描述】:
对不起,如果我在呈现这个的方式上犯了任何错误,但我的问题是在我为链表创建新节点之后,它是第一个重复节点(由用户名判断)创建了一个新节点,但所有其余的副本工作正常。
当要创建一个新节点时调用新名称(哈希表节点为 NULL),然后在创建下一个条目后,它看不到存在我认为的原始值 'if(temp->userName = = tempUser)' 将修复。任何帮助将不胜感激!
void linkedList::addNode(Node ** table, int hashLocation, string tempUser, string tempStart, string tempCPU, string tempPath, int tempPID)
{
Node * temp = table[hashLocation];
bool isTaken = false;
if(temp != NULL)
{
cout << "TEMP'S USERNAME = " << temp->userName << endl;
while (temp->next != NULL && isTaken == false) //&& tempUser != temp->userName)
{
cout << "USERNAME = " << temp->next->userName << "TEMPUSER = " << tempUser << endl;
if(temp->userName == tempUser) // PROBLEM HERE NOT BEING SET TO TAKEN
{
isTaken = true;
}
if(isTaken == false)
{
temp = temp->next;
}
}
cout << "Exited loop" << endl;
cout << "IS TAKEN = " << isTaken << endl;
if(isTaken == true)
{
cout << "ITS TAKEN" << endl;
string tempMinute, tempSecond;
temp->processID.push_back(tempPID);
istringstream iss(tempCPU);
getline(iss, tempMinute, ':');
getline(iss, tempSecond);
temp->minuteCount.push_back(atoi(tempMinute.c_str()));
temp->secondCount.push_back(atoi(tempSecond.c_str()));
temp->pathName.push_back(tempPath);
temp->timeStart.push_back(tempStart);
}
else
{
cout << "NOT TAKEN" << endl;
temp->next = new Node(tempUser, tempStart, tempCPU, tempPath, tempPID);
}
}
else
{
cout << "NEW NAME: " << tempUser << endl;
table[hashLocation] = new Node(tempUser, tempStart, tempCPU, tempPath, tempPID);
//cout << "TEMP'S USERNAME = " << temp->userName << endl;
}
}
class Node
{
public:
Node();
~Node();
Node(string tempUser, string tempStart, string tempCPU, string tempPath, int tempPID);
Node * next;
vector<int> processID, minuteCount, secondCount;
vector<string> pathName, timeStart;
string userName;
private:
};
这是来自 main 的调用
aList.addNode(aHash.getTable(), aHash.hashValue(tempUser), tempUser, tempStart, tempCPU, tempPath, tempPID);
我检查了它收到的值,它们都是正确的。
【问题讨论】:
-
不相关:每次在问题中发布图像代码或终端输出时,都会有一只小猫死亡。
标签: c++ linked-list hashtable nodes