Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions hash_table.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Author: Proma Roy
// GITHUB: https://github.com/promaroy

// hash table implementation for finding the frequency of each character in a string...

#include<bits/stdc++.h>
using namespace std;
int main()
{
string s="hacktoberfest";//string
int hash[26]={0};// initializing hash table to store the frequency of each character..

for(int i=0;i<s.length();i++)// looping through the string..
{
hash[s[i]-'a']++; // frequency of "a" stored at hash[0], frequency of "b" stored at hash[1] and so on..
}
for(int i=0;i<26;i++)
{
if(hash[i]!=0)
{
cout<<"Frequency of "<<char(i+'a')<<"- "<<hash[i]<<endl;
}
}

}