Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include<cstdlib>
  2. #include<iostream>
  3. #include <stack>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7.  
  8. struct kolejka
  9. {
  10. int a;
  11. kolejka *next;
  12. };
  13.  
  14.  
  15. kolejka *first = NULL;
  16. kolejka *last = NULL;
  17.  
  18.  
  19. void push(int nowea)
  20. {
  21.  
  22.  
  23. if(first == NULL)
  24. {
  25. kolejka *punkt = new kolejka;
  26. punkt -> a = nowea;
  27. punkt -> next = NULL;
  28. last = punkt;
  29. first = punkt;
  30. }
  31. else
  32. {
  33. kolejka *punkt = new kolejka;
  34. punkt -> a = nowea;
  35. punkt -> next = last;
  36. last = punkt;  
  37. }
  38. }
  39.  
  40.  
  41.  
  42. int pop()
  43. {
  44.  
  45.     if(last != NULL)
  46.     {
  47.     kolejka *pelem = last;
  48.     int a = last -> a;
  49.     last = pelem -> next;
  50.     delete pelem;
  51.     return a;  
  52.     }
  53.     else return 0;
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. void top()
  62. {
  63.     if(first == NULL) cout << "kolejka jest pusta" << endl;
  64.     else cout << "last = " << last -> a << endl;
  65.  
  66. }
  67.  
  68.  
  69.  
  70. ////////////////////////////////////////////////////////////////////////////////////
  71.  
  72. main()
  73. {
  74.    
  75. srand(time(NULL));
  76.  
  77.  
  78. for(int i = 0; i < 20; i++)
  79. {
  80. push(rand() % 100);
  81. }
  82.  
  83. int min = first -> a;
  84. kolejka * wsk = first;
  85.  
  86.  
  87. do
  88. {
  89.  
  90. if(wsk -> a < min) min = wsk -> a;
  91. wsk = wsk -> next ;
  92.  
  93.    
  94.    
  95.    
  96. }while(last != NULL);
  97.  
  98.  
  99. cout << "min " << min;
  100.  
  101.  
  102.  
  103.  
  104. system("pause");
  105. return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement