Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <list>
- #include <string.h>
- #include <fstream>
- #include <math.h>
- using namespace std;
- #define MOD 101
- #define SIZE 101
- int hash_func(string s)
- {
- int n = s.length();
- // declaring character array
- char name[n+1];
- // copying the contents of the
- // string to char array
- strcpy(name, s.c_str());
- int n1=2,n2=8;
- double sum=0;
- for(int i=0;i<strlen(name);i+=2)
- {
- sum=sum+(int)name[i]/pow(2,n1);
- }
- sum=sum*pow(2,n2);
- int d=int(sum)%MOD;
- return d;
- }
- class symbolInfo
- {
- public:
- string name;
- string type;
- };
- class symbolTable
- {
- public:
- list <symbolInfo> stable[SIZE];
- };
- int main()
- {
- // define as per your requirement
- ifstream thisfile("input.txt");
- char c;
- string name, type;
- symbolTable symtab;
- symbolInfo syminf;
- while(!thisfile.eof()){
- thisfile>>c;
- if(c=='I')
- {
- thisfile>>name>>type;
- syminf.name=name;
- syminf.type=type;
- cout<<c<<" "<<name<<" "<<type<<endl;
- int f=hash_func(syminf.name);
- cout<<f<<endl;
- symtab.stable[f].push_back(syminf);
- cout<<"<"<<" "<<name<<","<<type<<"> inserted at position ("<<f<<")"<<endl;
- }
- if(c=='L')
- {
- thisfile>>name;
- cout<<c<<" "<<name<<endl;
- }
- if(c=='P')
- {
- cout<<c<<endl;
- list <symbolInfo> :: iterator it;
- for(int i=0;i<101;i++)
- {
- cout<<i<<" ------>";
- for(it = symtab.stable[i].begin(); it != symtab.stable[i].end(); ++it)
- cout <<" <"<<(*it).name<<","<<(*it).type<<">";
- cout << '\n';
- }
- }
- if(c=='D')
- {
- thisfile>>name;
- int f=hash_func(name);
- //symtab.stable[f].remove();
- cout<<c<<" "<<name<<" "<<endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement