Napisałem stos obiektowy, chciałem spytać czy jest dobrze. I mam jeden problem do stosu s2 muszę przekopiować zawartość stosu s1. Ale do stosu s2 kopiuje elementy od tyłu, a chcę od przodu aby potem stosem s2 wyświetlało stos s1. Da się ?
#include <iostream>
using namespace std;
class stack
{
public:
int m_count;
int max_size;
int *tablica;
////////////////////////////////////////////////////////////////////////
void init(int max)
{
max_size = max;
m_count = 0;
tablica = new int [max_size];
}
////////////////////////////////////////////////////////////////////////
bool empty()
{
return m_count == 0; // !m_count
}
////////////////////////////////////////////////////////////////////////
bool full()
{
return m_count == max_size;
}
////////////////////////////////////////////////////////////////////////
void destroy()
{
while(Pop());
}
////////////////////////////////////////////////////////////////////////
void Push(int number)
{
if(m_count < max_size)
{
tablica[m_count++] = number;
}
}
////////////////////////////////////////////////////////////////////////
int Top(void)
{
if(m_count)
{
return tablica[--m_count];
}
}
////////////////////////////////////////////////////////////////////////
int Pop()
{
if(m_count)
{
--m_count;
return 1;
}
else return 0;
}
};
int main()
{
int number_user;
int count_number;
cout << "Podaj ilosc liczb ktore chcesz wlozyc na stos: ";
cin >> count_number;
stack s1;
stack s2;
s2.init(10);
s1.init(count_number);
cout << "\nPodawaj kolejne liczby stosu\n\n";
for(int i = 0; i < count_number; ++i)
{
cin >> number_user;
s1.Push(number_user);
}
for(int i = 0; i < count_number; ++i)
{
s2.Push(s1.Top());
}
cout << s2.Top();
return 0;
}