Code is running and not stopping

template
class Hashtable
{
struct node **table; ///pointer to an array of pointers
int current_size;
int table_size;

int hashfn(string key)
{
	int idx=0;
	int p=1;
	for(int j=0;key.length();j++)
	{
		idx=idx+(key[j]*p)%table_size;   ////meaning (a+b+c)%x==( (a%x+b%x+c%x) )%m
		idx=idx%table_size;
		p=(p*27)%table_size;             ////eg batman =b + 27*a + 27*27*t + 27*27*27*m.......
	}
	return idx;
}

public:
	Hashtable(int ts=7)     ///initially make an of size 7
	{
		table_size=ts;
		table=new node<T>*[table_size];
		current_size=0;
		for(int i=0;i<table_size;i++)
		{
			table[i]=0;
		}
	}
	void insert(string key,T value)
	{
		int idx=hashfn(key);
		struct node <T> *n=new node<T>(key,value);
		////Here we are inserting nodes at the head of the index eg 
		////we add node1 then node 2 then node3 now index will point to node2 and to node 2 and that to node1
		
		n->next=table[idx];
		table[idx]=n;
		current_size++;
	}
	
	void print()
	{
		for(int i=0;i<table_size;i++)
		{
			cout<<"Bucket:"<<i<<"->";
			struct node<T> *temp;
			temp=table[i];
			while(temp!=0)
			{
				cout<<temp->key<<" ";
				temp=temp->next;
			}
			cout<<endl;
		}
	}

};

int main()
{
Hashtable price_menu;
price_menu.insert(“Burger”,120);
price_menu.insert(“Pepsi”,200);
price_menu.insert(“BurgerPizza”,150);
price_menu.insert(“Noodles”,25);
price_menu.insert(“Coke”,40);
price_menu.print();
}

instead of this you have to write
while
(temp!=NULL)

i used that too it still didnt work

Send me link of code

template class Hashtable { struct node table; ///pointer to an array of pointers int current_size; int table_size; int hashfn(string key) { int idx=0; int p=1; for(int j=0;key.length();j++) { idx=idx+(key[j]p)%table_size; ////meaning (a+b+c)%x==( (a%x+b%x+c%x) )%m idx=idx%table_size; p=(p27)%table_size; ////eg batman =b + 27a + 2727t + 272727m… } return idx; } void rehash() { node oldtable=table; int oldtablesize=table_size; table_size=2table_size; ///just an approxiamation but it is better to find the nearest prime no table=new node[table_size]; for(int i=0;i<oldtablesize;i++) { table[i]=0; } current_size=0; /////NOw shift the elements form the old table to the new table for(int i=0;i<oldtablesize;i++) { nodetemp=oldtable[i]; while(temp!=0) { insert(temp->key,temp->value); temp=temp->next; } if(oldtable[i]!=NULL) ///Here we are deletingthe nodes of the oldtable before deleting the whole table to save space { delete oldtable[i]; } } delete [] oldtable; ///Noe delte the whole table } public: Hashtable(int ts=7) ///initially make an array of size 7 { table_size=ts; table=new node[table_size]; current_size=0; for(int i=0;i<table_size;i++) { table[i]=NULL; } } void insert(string key,T value) { int idx=hashfn(key); node n=new node(key,value); ////Here we are inserting nodes at the head of the index eg ////we add node1 then node 2 then node3 now index will point to node2 and to node 2 and that to node1 n->next=table[idx]; table[idx]=n; current_size++; ////rehash… float load_factor=current_size/1.0table_size; if(load_factor>0.7) { rehash(); } } void print() { for(int i=0;i<table_size;i++) { cout<<“Bucket:”<<i<<"->"; struct node temp; temp=table[i]; while(temp!=NULL) { cout<key<<" "; temp=temp->next; } cout<<endl; } } T search(string key) { int idx=hashfn(key); node *temp=table[idx]; while(temp!=NULL) { if(temp->key==key) { return &temp->value; } temp=temp->next; } return NULL; } }; int main() { Hashtable price_menu; price_menu.insert(“Burger”,120); price_menu.insert(“Pepsi”,200); price_menu.insert(“BurgerPizza”,150); price_menu.insert(“Noodles”,25); price_menu.insert(“Coke”,40); price_menu.print();

save your code at


and click on file then save
after that a link is generated at url send this to me
it will look like https://ide.codingblocks.com/s/1223

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.