#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;
struct Stack
{
int m_count;
int max_size;
int *tablica;
};
void Init(Stack *S,int max)
{
S->m_count = 0;
S->max_size = max;
S->tablica = new int [S->max_size];
}
bool Empty(Stack *S)
{
return S->m_count == 0;
}
bool Full(Stack *S)
{
return S->m_count == S->max_size;
}
void Push(Stack *S, int number)
{
if(S->m_count < S->max_size)
{
S->tablica[S->m_count++] = number;
}
}
int Top(Stack *S)
{
if(S->m_count)
{
return S->tablica[S->m_count - 1];
}
}
void Pop(Stack *S)
{
if(S->m_count)
{
--(S->m_count);
}
}
void Destroy(Stack *S)
{
delete [] S->tablica;
}
int main()
{
typedef struct Stack Stack;
Stack s1,s2;
int liczba = rand() % 100 + 1;
Stack *a = &s1;
Stack *b = &s2;
Init(a,liczba);
Init(b,liczba);
for(int i = 0; i < liczba; ++i)
{
Push(a,rand() % 100 + 1);
Push(b,rand() % 100 + 1);
}
cout << "Stos s1:" << setw(24) << "Stos s2:" << endl;
for(int i = 0; i < liczba; ++i)
{
cout << Top(a) << "\t\t\t";
Pop(a);
cout << Top(b) << endl;
Pop(b);
}
Destroy(a);
Destroy(b);
return 0;
}
Czy w funkcji Top,Pop i Push dać warunek else ?