Advertisement
Guest User

mapaZoznamov

a guest
Nov 25th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. // mapa zoznamov
  2. map<int,list<int>> mapaListov;
  3. map<int, list<int>>::iterator itMap;
  4. list<int>::iterator itListVMape;
  5.  
  6. // premenne pre random pridradenie prvkov do mapy
  7. int k = 10;
  8. int l = 1;
  9.  
  10. // naplnenie mapy zoznamov
  11.  
  12. for (int i = 0; i <10; i++)
  13. {
  14. list<int> list1;
  15. for (int j = 0; j < 10; j++)
  16. {
  17. list1.push_back(rand() % k + l);
  18. }
  19. mapaListov[i] = list1;
  20. k += 10;
  21. l += 10;
  22. }
  23.  
  24. int q = 0;
  25. itMap = mapaListov.begin();
  26. try
  27. {
  28. while (itMap != mapaListov.end())
  29. {
  30. itListVMape = mapaListov[q].begin();
  31. while (itListVMape != mapaListov[q].end())
  32. {
  33. cout << *itListVMape << " ";
  34. itListVMape++;
  35. }
  36. cout<< endl;
  37. q++;
  38. itMap++;
  39. }
  40. }
  41. catch (out_of_range &mess)
  42. {
  43. cout << "Nastala chyba: " << mess.what() << endl;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement