YouTubeでハッシュテーブルに関するビデオをフォローしていましたが、一部の出力をテストしているうちにコンソールがかなりの数の行をスキップしていることがわかりました。Visual Studio 2017 C++コンソールですべてが出力されない
私のハッシュテーブルのサイズはもともと10です。プログラムを実行すると、すべてが正しく表示されます。しかし、サイズを20にすると、私のコンソールは最初の3つのインデックスをスキップします。問題が自分のコードやVisual Studioにあるのかどうかはわかりませんが、ここの誰かが知りたいと思っていました。
これはサイズ20とコンソール出力の画像です:
サイズ10:
Hash::Hash() {
for (int i = 0; i < tableSize; i++) {
HashTable[i] = new item;
HashTable[i]->name = "empty";
HashTable[i]->drink = "empty";
HashTable[i]->next = NULL;
}
}
int Hash::hashFunction(std::string key) {
int hash = 0;
int index;
for (int i = 0; i < key.length(); i++) {
hash = (hash + (int)key[i]) * 17;
}
index = hash % tableSize;
return index;
}
void Hash::addItem(std::string name, std::string drink) {
int index = hashFunction(name);
if (HashTable[index]->name == "empty") {
HashTable[index]->name = name;
HashTable[index]->drink = drink;
}
else {
item* ptr = HashTable[index];
item* n = new item;
n->name = name;
n->drink = drink;
n->next = NULL;
while (ptr->next != NULL) {
ptr = ptr->next;
}
ptr->next = n;
}
}
int Hash::numItemsIndex(int index){
int count = 0;
if (HashTable[index]->name == "empty")
return count; //0
else {
count++;
item* ptr = HashTable[index];
while (ptr->next != NULL) {
count++;
ptr = ptr->next;
}
}
return count;
}
void Hash::printTable(){
int number;
for (int i = 0; i < tableSize; i++) {
number = numItemsIndex(i);
cout << "-------------------------\n";
cout << "Index = " << i << endl;
cout << HashTable[i]->name << endl;
cout << HashTable[i]->drink << endl;
cout << "# of items = " << number << endl;
cout << "-------------------------\n";
}
}
void Hash::printItemsInIndex(int index){
item* Ptr = HashTable[index];
if (Ptr->name == "empty")
cout << "Index " << index << " is empty. \n";
else {
cout << "Index " << index << " contains the following items: \n";
while (Ptr != NULL) {
cout << "-------------------------\n";
cout << Ptr->name << endl;
cout << Ptr->drink << endl;
cout << "-------------------------\n";
Ptr = Ptr->next;
}
}
}
int main(int argc, char* argv[]) {
Hash Hashy; //create of tablesize 10 and initialize
// all with items -> empty, empty, NUll.
Hashy.addItem("Paul", "Locha");
Hashy.addItem("Kim", "Iced Mocha");
Hashy.addItem("Emma", "Strawberry Smoothie");
Hashy.addItem("Annie", "Hot Chocolate");
Hashy.addItem("Sarah", "Passion Tea");
Hashy.addItem("Pepper", "Caramel Mocha");
Hashy.addItem("Mike", "Chai Tea");
Hashy.addItem("Steve", "Apple Cider");
Hashy.addItem("Bill", "Root Beer");
Hashy.addItem("Marie", "Skinny Latte");
Hashy.addItem("Susan", "Water");
Hashy.addItem("Joe", "Green Tea");
Hashy.printTable();
//Hashy.printItemsInIndex(8);
system("pause");
return 0;
}
いくつかのものは、出力部にありますが、私は彼らの意味を知らない:
'LetsHash.exe' (Win32): Loaded 'C:\Users\Rohan Vidyarthi\Desktop\LetsHash\Debug\LetsHash.exe'. Symbols loaded. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\kernel32.dll' 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\WRusr.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140d.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\win32u.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32full.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\windows.storage.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\combase.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbase.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\powrprof.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\SHCore.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\profapi.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\psapi.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_32.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wininet.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleacc.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp_win.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\urlmon.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\secur32.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msimg32.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\iertutil.dll'. Cannot find or open the PDB file. 'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Cannot find or open the PDB file. The thread 0xbc8 has exited with code 252968960 (0xf140000). The thread 0x1700 has exited with code 0 (0x0). The thread 0x19bc has exited with code 0 (0x0). The thread 0x1b70 has exited with code 0 (0x0). The program '[3484] LetsHash.exe' has exited with code 0 (0x0).
これはデバッガで表示される通常の出力であり、プログラムとは関係ありません。あなたは誰でもあなたの問題を推測するだけの十分なコードを表示していません。あなたの出力の写真は、必要でも有益でもありませんが、その出力を生成するコードはです。 –
あなたのコードに問題があります。あなたはそのすべてを投稿していないので、エラーが正確にどこにあるかを言うことは不可能です。 [mcve]についてお読みください。また、[デバッグ](https://www.google.co.il/amp/s/ericlippert.com/2014/03/05/how-to-debug-small-programs/amp/)コードを読んで、試してみてください。 –
2番目の画像にスクロールバーが表示されます。誰もそれが何を考えているかは分かりません。テキストターミナルの写真は投稿しないでください。ほとんど役に立たないです。代わりにあなたのプログラム出力の実際のテキストをポストする(すべてがウィンドウに収まるだけでなく)。 –