#include #include #include using namespace std; class keyword { // uncomment 1st n 3rd line, later //string original_keyword; // actual keyword int hashed_keyword; // hash value of keyword which you hav to compare //vector indexes; public: keyword(); keyword(int); int get_HKW(); //get Hashed Key Word static vector HKWsearch_insert( vector V, int hashed_input); void initialize(int); // just for time sake... to be deleted }; keyword::keyword() { } keyword::keyword(int value) { keyword::hashed_keyword=value; } void keyword::initialize(int value) { keyword::hashed_keyword=value; } int keyword:: get_HKW() { return keyword::hashed_keyword; } vector keyword:: HKWsearch_insert( vector V, int hashed_input) { keyword temporary(hashed_input); //cout<<"enter the keyword\n"; //string keyworde; //cin>>keyworde; //sample_one.original_keyword=keyworde; //hash it and //searching part int l=0,h=V.size()-1; int temp,mid,pos; while(l hashed_input ) { temp = h-1; //possible pos to insert new hashed_input while( V[temp].get_HKW() == V[h].get_HKW() ) temp--; pos = temp; goto insert; } } if(V[mid].get_HKW() == hashed_input) { pos = (mid+1); goto insert; } if(V[mid].get_HKW() < hashed_input) l=mid+1; if(V[mid].get_HKW()> hashed_input) h=mid-1; } // end of while insert:int temp1; temp1= V.size(); V.resize(V.size()+1); while( temp1 >= pos) { V[temp1+1]=V[temp1]; temp1--; } V[temp1]= temporary ; //copying classes } int main() // later rename main() appropriately n put into library { int hashed_input= 250 ; // remove later /* i will create a pseudo keyword * objects to test the function * delete this portion later*/ vector V(20); //works only when there is a default constructor else // vetor V(200, keyword(/*arguments for constructor */)); // use a vector of size 1. (not 200) As real database is built, it is resized with each insertion for(int i=0; i<20 ; i++) { V[i].initialize(i+100); //current no. of elements(a static member of V) } keyword::HKWsearch_insert( V, hashed_input); for (int i=0;i