我對這個網站不熟悉,並且會盡力按照我的要求做出貢獻。此外,請知道我從來沒有花費太多時間試圖自己弄清楚問題。因此,C++ Stacks讓我瘋狂。對C++堆棧使用感到困惑
我的問題:我在哪裏將我的變量/值放在堆棧功能塊中以實際使用它。我明白棧是一個LIFO數據結構,我讀過這段代碼在彼此的頂部堆疊板等
看的例子不勝枚舉:
#include <iostream>
using namespace std;
const int MAX_SIZE = 100;
class StackOverFlowException
{
public:
StackOverFlowException()
{
cout << "Stack overflow" << endl;
}
};
class StackUnderFlowException
{
public:
StackUnderFlowException()
{
cout << "Stack underflow" << endl;
}
};
class ArrayStack
{
private:
int data[MAX_SIZE];
int top;
public:
ArrayStack()
{
top = -1;
}
void Push(int element)
{
if (top >= MAX_SIZE)
{
throw new StackOverFlowException();
}
data[++top] = element;
}
int Pop()
{
if (top == -1)
{
throw new StackUnderFlowException();
}
return data[top--];
}
int Top()
{
return data[top];
}
int Size()
{
return top + 1;
}
bool isEmpty()
{
return (top == -1) ? true : false;
}
};
[等等... 。]
這是基本的餅乾.... 比方說,我試圖調整它,以表達一個系統,最後的食物訂單放在哪裏,先被踢出;變量是'食物','訂單'以及其他任何東西。 我在世界的哪個地方將這些變量集成到上面的堆棧代碼中!?!??!
請幫助很困惑我即將胡亂衝的東西
這將是一個可怕的餐廳。 –
基本上你想「推」你的訂單在堆棧上,然後「彈出」它們。 – Sword22
第一個訂購的人永遠等待...... – dreamlax