#include <iostream>
using namespace std;
struct stack
{
int number;
stack* next;
};
void push(stack** top, int number)
{
stack* temp = new stack;
temp->number = number;
temp->next = *top;
*top = temp;
}
void show(stack* top)
{
stack* temp = top;
while (temp != nullptr)
{
cout << temp->number << " ";
temp = temp->next;
}
}
void cleanStack(stack** top)
{
stack* temp;
while (*top != nullptr)
{
temp = *top;
*top = (*top)->next;
delete temp;
}
}
int main()
{
setlocale(LC_ALL, "Russian");
stack* top = nullptr;
int num;
int a;
cout << "Введите количество элементов в стеке: ";
cin >> num;
for (int i = 0; i < num; i++)
{
cout << i << " элемент стека: ";
cin >> a;
push(&top, a);
}
cout << endl << endl;
if (top == nullptr)
cout << "Стек пуст!!!" << endl;
show(top);
stack* temp = top->next;
stack* ttemp = nullptr;
// сортировка ????
while (true)
{
if (temp->next = nullptr) break;
ttemp = temp;
temp = top;
top = ttemp;
top->next;
temp->next;
}
cout << endl;
show(top);
cleanStack(&top);
return 0;
}