<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hash Table | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/hash-table/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Mon, 31 Jan 2011 12:01:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>C++ program to implement Hash Table</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-hash-table/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-hash-table/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Mon, 31 Jan 2011 12:01:56 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[linked list]]></category>
		<category><![CDATA[Hash Table]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1263</guid>

					<description><![CDATA[<p>#include #include #include template class HashTable { public: HashTable(int divisor = 11); ~HashTable() {delete [] ht; delete [] empty;} int Search(const K&#038; k, E&#038; e) const; HashTable&#038; Insert(const E&#038; e); void Output();// output the hash table void del(E e); private: int hSearch(const K&#038; k) const; int D; // hash function divisor E *ht; // hash</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-hash-table/">C++ program to implement Hash Table</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include <iostream.h>
#include <stdlib.h>
#include<constream.h>
template<class E, class K>
class HashTable {
	public:
		HashTable(int divisor = 11);
		~HashTable() {delete [] ht;
			delete [] empty;}
			int Search(const K& k, E& e) const;
			HashTable<E,K>& Insert(const E& e);
			void Output();// output the hash table
			void del(E e);
	private:
			int hSearch(const K& k) const;
			int D; // hash function divisor
			E *ht; // hash table array
			int *empty; // 1D array
};
	template<class E, class K>
HashTable<E,K>::HashTable(int divisor)
{// Constructor.
	D = divisor;
	ht = new E [D];
	empty = new int [D];

	for (int i = 0; i < D; i++)
		empty[i] = 1;
}
template<class E, class K>
int HashTable<E,K>::hSearch(const K& k) const
{
	int i = k % D;  
	int j = i;     
	do {
		if (empty[j] || ht[j] == k) return j;
		j = (j + 1) % D;  // next bucket
	} while (j != i); // returned to home?
	return j;  // table full
}
	template<class E, class K>
void HashTable<E,K>::del(E e)
{
	int b=hSearch(e);
	if( !empty[b] && ht[b]==e)
	{
		ht[b]=0;
		empty[b]=1;
	}
	else
		cout<<"element not found";

}
template<class E, class K>
int HashTable<E,K>::Search(const K& k, E& e) const
{
	int b = hSearch(k);
	if (empty[b] || ht[b] != k) return 0;
	e = ht[b];
	return 1;
}
	template<class E, class K>
HashTable<E,K>& HashTable<E,K>::Insert(const E& e)
{// Hash table insert.
	K k = e; // extract key
	int b = hSearch(k);
	if (empty[b]) {empty[b] = 0;
		ht[b] = e;
		return *this;

	}
	if (ht[b] == k) { cout<<"bad input"; return *this; } // duplicate
	cout<<"No memory";// table full
	return *this;
}

	template<class E, class K>
void HashTable<E,K>::Output()
{
	cout<<endl;
	for (int i = 0; i< D; i++) {
		if (empty[i]) cout << "0 ";
		else cout << ht[i]<<" ";}
	cout<<endl;
}
class element {
	friend void main(void);
	public:
	operator long() const {return key;}
	private:
	int data;
	long key;
};
void main(void)
{
	clrscr();
	HashTable<int , int > h(11);
	int e;
	e = 80;
	h.Insert(e);
	e = 40;
	h.Insert(e);
	e = 65;
	h.Insert(e);
	cout<<"After inserting 80,40,65:";
	h.Output();
	cout<<endl;
	h.del(40);
	cout<<"After deleting 40:";
	h.Output();
	cout<<endl;
	e = 58;
	h.Insert(e);
	e = 24;
	h.Insert(e);
	cout<<"after appending 58, 24:";
	h.Output();
	cout<<"Trying to delete element 25:";
	h.del(25);
	h.Output();
	e = 2;
	h.Insert(e);
	e = 13;
	h.Insert(e);
	e = 46;
	h.Insert(e);
	e = 16;
	h.Insert(e);
	e = 7;
	h.Insert(e);
	e = 21;
	h.Insert(e);
	h.Insert(10);
	cout <<"After inserting more values:" << endl;
	h.Output();
	e = 99;
	cout<<"trying to insert 99:";
	h.Insert(e);
	h.Output();
	getch();
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-hash-table/">C++ program to implement Hash Table</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-hash-table/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
