Я работал над проектом, который должен моделировать список ссылок, используя 2D-массив для стеков. У меня есть код, но я не могу понять, как заставить работать случайные числа. Я искал в Интернете, но в Интернете не объясняется, как заставить случайную функцию работать с симуляцией. Вот мой код ниже:
`#include <iostream>
#include <stdlib.h>
using namespace std;
int myTop = -1;
int index = -1;
int next = -1;
int tt[25][2];
void construct()
{
tt[25][2];
}
void empty()
{
if (myTop == -1)
cout << "Empty Stack";
else
cout << "Full Stack";
}
void push(int x)
{
if (myTop < 24)
{
myTop++;
tt[myTop] = x;
}
else
cout << "The stack is full.";
}
void top()
{
if (myTop != -1)
cout << "Top Value is: " << tt[myTop];
else
cout << "Empty Stack";
}
int pop()
{
int x;
if(myTop<=0)
{
cout<<"stack is empty"<<endl;
return 0;
}
else
{
x=tt[myTop];
myTop--;
}
return(x);
}
void display()
{
for (int row=0; row<25; row++)
{
for (int column=0; column<3; column++)
{
cout << tt[row][column] << "\t";
if (column == 2)
cout << endl;
}
}
cout << endl;
}
int main()
{
push(rand() % 25);
display();
push(rand() % 25);
display();
push(rand() % 25);
display();
push(rand() % 25);
display();
top();
pop();
display();
top();
pop();
display();
top();
pop();
display();
}