Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PO8.04.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <ctime>
- namespace struktury
- {
- const static int maxRozmiar = 50;
- namespace tablicowe
- {
- class Stos{
- public:
- int szczyt;
- int tab[50];
- Stos()
- {
- szczyt = 0;
- }
- void push(int el)
- {
- tab[szczyt++] = el;
- }
- void pop()
- {
- szczyt--;
- }
- int top()
- {
- return tab[szczyt - 1];
- }
- bool empty()
- {
- if (szczyt == 0)
- return true;
- else
- return false;
- }
- bool Full()
- {
- if (szczyt == maxRozmiar)
- return true;
- else
- return false;
- }
- }
- ;
- }
- namespace listowe
- {
- class Elem {
- public:
- int l;
- Elem *nast;
- };
- class Stos {
- public:
- int szczyt;
- Elem *ostatni;
- Stos()
- {
- szczyt = 0;
- ostatni = NULL;
- }
- void pop() {
- Elem* tmp = ostatni;
- ostatni = ostatni->nast;
- szczyt--;
- delete tmp;
- }
- void push(int l) {
- Elem* nowy = new Elem;
- nowy->nast = ostatni;
- nowy->l = l;
- ostatni = nowy;
- szczyt++;
- }
- int top() { return ostatni->l; }
- bool full() {
- if (szczyt == maxRozmiar)
- return true;
- else
- return false;
- }
- bool empty() {
- if (szczyt == 0)
- return true;
- else
- return false;
- }
- ~Stos()
- {
- while (!this->empty()) {
- this->pop();
- }
- }
- };
- }
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- srand(time(NULL));
- using namespace struktury::listowe;
- {
- Stos s1;
- for (int i = 0; i < 10; i++)
- s1.push(rand()%100);
- for (int i = 0; i < 10; i++)
- {
- std::cout << s1.top() << std::endl;
- s1.pop();
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement