C++/ptl/HashTable.hpp
// Prints hash table data in a table shaped format

Prints hash table data in a table shaped format
Prints hash table data in a table shaped format
void HashTable::printTable() const
	{
		int nameMaxLength = 0, temp = 0;
		int maxIndex = 0, maxIndexLength = 0;
		int blankDiff = 0, indexLength = 0;
		for (int i = 0; i < table_size; i++)
		{
			if (table[i].first.length() > nameMaxLength)
				nameMaxLength = table[i].first.length();
			if (table[i].second > maxIndex)
				maxIndex = table[i].second;
		}
		if (maxIndex <= 0)
		{
			nameMaxLength = 5;
			maxIndex = 999;
		}
		temp = maxIndex;
		while (temp != 0)
		{
			temp /= 10;
			maxIndexLength++;
		}
		std::cout << "|";
		for (int i = 0; i < nameMaxLength + maxIndexLength + 5; ++i)
			std::cout << "-";
		if (maxIndexLength < 2)
			std::cout << "-";
		std::cout << "|" << std::endl;
		std::cout << "| ";
		for (int i = 0; i < (nameMaxLength - 1)/2; ++i)
			std::cout << " ";
		std::cout << "K";
		for (int i = 0; i < (nameMaxLength - 1)/2; ++i)
			std::cout << " ";
		if ((nameMaxLength - 1) %2 != 0)
			std::cout << " ";
		std::cout << " | ";
		for (int i = 0; i < (maxIndexLength - 1)/2; ++i)
			std::cout << " ";
		if ((maxIndexLength - 1) % 2 != 0)
			std::cout << " ";
		std::cout << "I";
		if (maxIndexLength < 2)
			std::cout << " ";
		for (int i = 0; i < (maxIndexLength - 1)/2; ++i)
			std::cout << " ";
		std::cout << " |" << std::endl;
		std::cout << "|";
		for (int i = 0; i < nameMaxLength + maxIndexLength + 5; ++i)
			std::cout << "-";
		if (maxIndexLength < 2)
			std::cout << "-";
		std::cout << "|" << std::endl;
		for (int i = 0; i < table_size; i++)
		{
			indexLength = 0;
			blankDiff = nameMaxLength - table[i].first.length();
			std::cout << "|";
			for (int j = 0; j < (blankDiff/2) + 1; j++)
				std::cout << " ";
			std::cout << table[i].first;
			for (int j = 0; j < (blankDiff/2) + 1; j++)
				std::cout << " ";
			if (blankDiff % 2 != 0)
				std::cout << " ";
			std::cout << "|";
			temp = table[i].second;
			while(temp != 0)
			{
				temp /= 10;
				indexLength++;
			}
			blankDiff = maxIndexLength - indexLength;
			for (int j = 0; j < (blankDiff/2) + 1; j++)
				std::cout << " ";
			std::cout << table[i].second;
			for (int j = 0; j < blankDiff/2; j++)
				std::cout << " ";
			if (table[i].second > 0)
				std::cout << " ";
			if (table[i].second == -1 && (maxIndexLength % 2 != 0 && maxIndexLength < 2))
				std::cout << " ";
			else if (table[i].second == -1 && maxIndexLength % 2 == 0)
				std::cout << " ";
			if (blankDiff % 2 != 0 && table[i].second > 0)
				std::cout << " ";
			if (table[i].second > 0 && maxIndexLength < 2)
				std::cout << " ";
			if (table[i].second == -99 && (maxIndexLength % 2 != 0 && maxIndexLength > 1))
				std::cout << " ";
			std::cout << "|" << std::endl;
			std::cout << "|";
			for (int i = 0; i < nameMaxLength + maxIndexLength + 5; ++i)
				std::cout << "-";
			if (maxIndexLength < 2)
				std::cout << "-";
			std::cout << "|" << std::endl;
		}
	}
void HashTable :: printTable ( ) const { int nameMaxLength = 0 , temp = 0 ; int maxIndex = 0 , maxIndexLength = 0 ; int blankDiff = 0 , indexLength = 0 ; for ( int i = 0 ; i < table_size ; i ++ ) { if ( table [ i ] . first . length ( ) > nameMaxLength ) nameMaxLength = table [ i ] . first . length ( ) ; if ( table [ i ] . second > maxIndex ) maxIndex = table [ i ] . second ; } if ( maxIndex <= 0 ) { nameMaxLength = 5 ; maxIndex = 999 ; } temp = maxIndex ; while ( temp != 0 ) { temp /= 10 ; maxIndexLength ++ ; } std :: cout << " " ; for ( int i = 0 ; i < nameMaxLength + maxIndexLength + 5 ; ++ i ) std :: cout << " " ; if ( maxIndexLength < 2 ) std :: cout << " " ; std :: cout << " " << std :: endl ; std :: cout << " " ; for ( int i = 0 ; i < ( nameMaxLength - 1 ) / 2 ; ++ i ) std :: cout << " " ; std :: cout << " " ; for ( int i = 0 ; i < ( nameMaxLength - 1 ) / 2 ; ++ i ) std :: cout << " " ; if ( ( nameMaxLength - 1 ) % 2 != 0 ) std :: cout << " " ; std :: cout << " " ; for ( int i = 0 ; i < ( maxIndexLength - 1 ) / 2 ; ++ i ) std :: cout << " " ; if ( ( maxIndexLength - 1 ) % 2 != 0 ) std :: cout << " " ; std :: cout << " " ; if ( maxIndexLength < 2 ) std :: cout << " " ; for ( int i = 0 ; i < ( maxIndexLength - 1 ) / 2 ; ++ i ) std :: cout << " " ; std :: cout << " " << std :: endl ; std :: cout << " " ; for ( int i = 0 ; i < nameMaxLength + maxIndexLength + 5 ; ++ i ) std :: cout << " " ; if ( maxIndexLength < 2 ) std :: cout << " " ; std :: cout << " " << std :: endl ; for ( int i = 0 ; i < table_size ; i ++ ) { indexLength = 0 ; blankDiff = nameMaxLength - table [ i ] . first . length ( ) ; std :: cout << " " ; for ( int j = 0 ; j < ( blankDiff / 2 ) + 1 ; j ++ ) std :: cout << " " ; std :: cout << table [ i ] . first ; for ( int j = 0 ; j < ( blankDiff / 2 ) + 1 ; j ++ ) std :: cout << " " ; if ( blankDiff % 2 != 0 ) std :: cout << " " ; std :: cout << " " ; temp = table [ i ] . second ; while ( temp != 0 ) { temp /= 10 ; indexLength ++ ; } blankDiff = maxIndexLength - indexLength ; for ( int j = 0 ; j < ( blankDiff / 2 ) + 1 ; j ++ ) std :: cout << " " ; std :: cout << table [ i ] . second ; for ( int j = 0 ; j < blankDiff / 2 ; j ++ ) std :: cout << " " ; if ( table [ i ] . second > 0 ) std :: cout << " " ; if ( table [ i ] . second == -1 && ( maxIndexLength % 2 != 0 && maxIndexLength < 2 ) ) std :: cout << " " ; else if ( table [ i ] . second == -1 && maxIndexLength % 2 == 0 ) std :: cout << " " ; if ( blankDiff % 2 != 0 && table [ i ] . second > 0 ) std :: cout << " " ; if ( table [ i ] . second > 0 && maxIndexLength < 2 ) std :: cout << " " ; if ( table [ i ] . second == -99 && ( maxIndexLength % 2 != 0 && maxIndexLength > 1 ) ) std :: cout << " " ; std :: cout << " " << std :: endl ; std :: cout << " " ; for ( int i = 0 ; i < nameMaxLength + maxIndexLength + 5 ; ++ i ) std :: cout << " " ; if ( maxIndexLength < 2 ) std :: cout << " " ; std :: cout << " " << std :: endl ; } }
Prints hash table data in a table shaped format
Prints hash table data in a table shaped format