Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unordered_map>
- #include <list>
- #include <string>
- #include <bits/stdc++.h>
- #include <time.h>
- using namespace std;
- //Abdallah Jehad Sami Kishawi (CS) 17007230
- //Struct that is used for LinkedList
- struct node
- {
- string text ;
- int count = 0 ;
- };
- int main(){
- //clock declaration
- clock_t start;
- clock_t stop;
- double ExecTime=0;
- double ExecTime2=0;
- //unordered_map & LinkedList
- unordered_map <string, int> umap;
- list<node> mylist;
- list<node>::iterator it;
- node INPUT;
- //string and stringstream
- string Line = "you are are here here in ADS ADS lab lab lab";
- stringstream x(Line);
- string word;
- stringstream y(Line);
- //String to map
- start = clock();
- while (x>>word)
- umap[word]++;
- stop = clock();
- ExecTime = (double)(stop - start) * 1000.0 / CLOCKS_PER_SEC;
- //String to list
- int count;
- start = clock();
- while (y>>word){
- count = 1;
- for(it = mylist.begin(); it != mylist.end(); ++it){
- if (it->text == word){
- count +=1;
- }
- }
- INPUT.text = word;
- INPUT.count = count;
- mylist.push_back(INPUT);
- }
- stop = clock();
- ExecTime2 = (double)(stop - start) * 1000.0 / CLOCKS_PER_SEC;
- //---Print Time Taken---//
- cout<<"Time Taken to execute MAP (ms): "<< ExecTime<<endl;
- cout<<"Time Taken to execute LIST (ms): "<< ExecTime2<<endl;
- /* (Uncomment to use) This is for printing the linked list
- for(it = mylist.begin(); it != mylist.end(); ++it){
- cout << it->text <<" "<< it->count << ",\n";
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement