Skip to Content
C++ Data Structures and Algorithms
book

C++ Data Structures and Algorithms

by Wisnu Anggoro
April 2018
Intermediate to advanced content levelIntermediate to advanced
322 pages
6h 57m
English
Packt Publishing
Content preview from C++ Data Structures and Algorithms

Developing a PrintHashTable() operation

By iterating the hash table, we can collect the pairs of key and value, then print them to the screen. We will use this PrintHashTable() operation to see if the new element we insert is stored in the right place. The implementation of the operation will be as follows:

void HashTable::PrintHashTable(){    // Iterate through array    for(int i = 0 ; i < currentSize; ++i)    {        // Just print the element        // if it exist        if(arr[i] != NULL && arr[i]->Key != -1)        {            cout << "Cell: " << i;            cout << " Key: " << arr[i]->Key;            cout << " Value: " << arr[i]->Value;            cout << std::endl;        }    }}

Since the operation will iterate through the hash table until the size of the table, the time complexity of this operation is O(TABLE_SIZE) ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Data Structures and Algorithms Using C++

Data Structures and Algorithms Using C++

Ananda Rao Akepogu, Radhika Raju Palagiri
C++ Data Structures and Algorithm Design Principles

C++ Data Structures and Algorithm Design Principles

John Carey, Anil Achary, Shreyans Doshi, Payas Rajan
C++ Plus Data Structures, 6th Edition

C++ Plus Data Structures, 6th Edition

Nell Dale, Chip Weems, Tim Richards

Publisher Resources

ISBN: 9781788835213Supplemental Content