Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<ctime>
- #include<cstdlib>
- #include<windows.h>
- using namespace std;
- int main() {
- srand(time(NULL));
- int index = 0;
- float rand01;
- const int wielkosc_stosu = 20;
- int id = 1000; //id dokumentu
- float p; //Prawdopodobienstwo polozenia dokumentu na stosie
- int wierzcholek = 0; // Wierzcholek stosu
- int x;
- //Stwórz i wypełnij tablicę
- int stos[wielkosc_stosu];
- for (int i = 0; i < wielkosc_stosu-1; i++)
- {
- stos[i] = (rand() % 1000) + 1;
- }
- cout << "Podaj prawdopodobienstwo (0.00 do 1.00): ";
- cin >> p;
- cout << endl;
- do {
- rand01 = (rand() % 99);
- rand01 /= 100;
- cout << "Losowa: " << rand01 << endl;
- if (rand01 < p) {
- stos[wierzcholek] = id;
- cout << "Polozenie dokumentu o ID " << id << " na stosie. " << endl;
- }
- else {
- if (wierzcholek > 0) {
- x = stos[wierzcholek - 1];
- cout << "Pobranie dokumentu o ID " << x << " ze stosu. " << endl;
- cout << "Zwalnianie miejsca dokumentu o ID " << x << endl;
- stos[wierzcholek] == NULL; //Zwalnianie miejsca dokumentu
- }
- else {
- cout << "Na stosie nie ma dokumentu, ktory mozna pobrac. " << endl;
- }
- }
- cout << endl;
- wierzcholek++;
- id++;
- index++;
- Sleep(3000);
- } while (index != 19);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement