Advertisement
cunha1

Untitled

Jul 4th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. struct element {
  9.     int broj;
  10.     element* sljedeci;
  11. };
  12.  
  13. int main() {
  14.     srand(time(0));
  15.     rand();
  16.     element* lista = NULL;
  17.     element* prosliElement;
  18.     int n;
  19.     int brojacManjiod200=0;
  20.     do {
  21.         n = (rand()%500) + 1;
  22.  
  23.         if(n<200) brojacManjiod200++;
  24.  
  25.         element* novi = new element;
  26.         novi->broj = n;
  27.         novi->sljedeci = NULL;
  28.        
  29.         if(lista==NULL)
  30.             lista=novi;
  31.         else
  32.             prosliElement->sljedeci=novi;
  33.        
  34.         prosliElement=novi;
  35.     }
  36.     while(n!=400);
  37.  
  38.     // prekopirati sadrzaj liste u dva polja, jedna za vece brojeve i jedna za manje
  39.     int *manjiod200 = new int[brojacManjiod200];
  40.     int iManjiod200=0;
  41.  
  42.     element *el = lista;
  43.     while(el!=NULL) {
  44.         if(el->broj < 200) {
  45.             manjiod200[iManjiod200++] = el->broj;
  46.         }
  47.         el=el->sljedeci;
  48.     }
  49.  
  50.  
  51.     // ovo je countsort, automatski sortira i broji
  52.     int brojPonavljanja[201] = {0};
  53.     for(int i=0;i<iManjiod200;i++) {
  54.         brojPonavljanja[manjiod200[i]]++;
  55.     }
  56.  
  57.     ofstream dat("datoteka.txt");
  58.  
  59.     for(int i=0;i<201;i++) {
  60.         if(brojPonavljanja[i]>0)
  61.             dat << i << " " << brojPonavljanja[i] << endl;
  62.     }
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement