Advertisement
Guest User

week8 lab

a guest
Feb 27th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <list>
  4. #include <string>
  5. #include <bits/stdc++.h>
  6. #include <time.h>
  7. using namespace std;
  8.  
  9. //Abdallah Jehad Sami Kishawi (CS) 17007230
  10.  
  11.  
  12. //Struct that is used for LinkedList
  13. struct node
  14. {
  15.     string text ;
  16.     int count = 0 ;
  17. };
  18.  
  19. int main(){
  20.     //clock declaration
  21.     clock_t start;
  22.     clock_t stop;
  23.     double ExecTime=0;
  24.     double ExecTime2=0;
  25.    
  26.     //unordered_map & LinkedList
  27.     unordered_map <string, int> umap;
  28.    
  29.     list<node>   mylist;
  30.     list<node>::iterator it;
  31.     node INPUT;
  32.    
  33.     //string and stringstream
  34.     string Line = "you are are here here in ADS ADS lab lab lab";
  35.     stringstream x(Line);
  36.     string word;
  37.     stringstream y(Line);
  38.    
  39.     //String to map
  40.     start = clock();
  41.     while (x>>word)
  42.         umap[word]++;
  43.     stop = clock();
  44.     ExecTime = (double)(stop - start) * 1000.0 / CLOCKS_PER_SEC;
  45.    
  46.    
  47.     //String to list
  48.     int count;
  49.     start = clock();
  50.     while (y>>word){
  51.         count = 1;
  52.         for(it = mylist.begin(); it != mylist.end(); ++it){
  53.             if (it->text == word){
  54.                 count +=1;
  55.             }
  56.         }
  57.         INPUT.text = word;
  58.         INPUT.count = count;
  59.         mylist.push_back(INPUT);
  60.     }
  61.     stop = clock();
  62.     ExecTime2 = (double)(stop - start) * 1000.0 / CLOCKS_PER_SEC;
  63.    
  64.  
  65.                 //---Print Time Taken---//
  66.     cout<<"Time Taken to execute MAP  (ms): "<< ExecTime<<endl;
  67.     cout<<"Time Taken to execute LIST (ms): "<< ExecTime2<<endl;
  68.    
  69.    
  70.    /* (Uncomment to use)   This is for printing the linked list
  71.    
  72.     for(it = mylist.begin(); it != mylist.end(); ++it){
  73.                 cout << it->text <<" "<< it->count << ",\n";
  74.         }
  75.     */
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement