本文整理汇总了C++中MyStack::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ MyStack::empty方法的具体用法?C++ MyStack::empty怎么用?C++ MyStack::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyStack
的用法示例。
在下文中一共展示了MyStack::empty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: char_test
void char_test()
{
char next;
MyStack<char> s;
cout << "Enter some text\n";
// read characters in one by one until newline reached
cin.get(next);
while (next != '\n') {
// push latest character
s.push(next);
cin.get(next);
}
cout << "Written backward that is:\n";
// output all characters stored in stack
while (!s.empty())
cout << s.pop();
cout << "\n";
}
示例2: string_test
void string_test()
{
string next;
char c;
MyStack<string> s;
cout << "Enter a sentence or two\n";
// read from terminal word by word
while (cin >> next) {
// put latest word into stack
s.push(next);
// was that the last word on the line?
c = cin.get();
if (c == '\n')
break;
else
cin.putback(c);
}
cout << "Written backward that is:\n";
while (!s.empty())
cout << s.pop() << " ";
cout << "\n";
}
示例3: test_qa
void test_qa(AnsType& expectAns, OpreateType& opreateParam, InitType& initData, DataType1 firstData = DataType1()) {
AnsType ans;
MyStack work;
for(int i=0; i<opreateParam.size(); i++) {
int ansTmp = -1;
if(opreateParam[i] == "push") {
work.push(firstData[i]);
}
if(opreateParam[i] == "pop") {
ansTmp = work.pop();
}
if(opreateParam[i] == "top") {
ansTmp = work.top();
}
if(opreateParam[i] == "empty") {
ansTmp = work.empty();
}
ans.push_back(ansTmp);
}
int index = getIndex();
bool check = eq(ans, expectAns);
if(!check) {
printf("index %d: NO\n", index);
output("opreateParam", opreateParam);
output("initData", initData);
output("firstData", firstData);
output("ans", ans);
output("expectAns", expectAns);
} else {
printf("index %d: YES\n", index);
}
printf("\n");
}
示例4: pop
bool StackWithMin::pop(int& d){
if(empty())
return false;
d = head->data;
Node* p = head;
head = head->next;
delete p;
--size;
if(d==minValue){
minS.pop(minValue);
minS.top(minValue);
if(minS.empty())
minValue = INT_MAX;
}
return true;
}
示例5: testStack
void testStack() {
MyStack s;
for(int i = 1; i <= 10; i++)
s.push(i);
MyStack s2 = s;
cout << "s:\n";
while (!s.empty())
cout << s.pop() << endl;
MyStack s3;
s3 = s;
for(int i = 11; i <= 20; i++)
s.push(i);
cout << "s2:\n";
while (!s2.empty())
cout << s2.pop() << endl;
cout << "Живи сме!\n";
}
示例6: main
int main() {
MyStack<int> st;
for (int i = 0; i < 100; i++)
st.push(i);
std::cout << st.size() << std::endl << std::endl;
for (int i = 0; i < 10; i++)
st.pop();
std::cout << st.size() << std::endl << std::endl;
for (int i = 0; i < 10; i++)
st.push(i);
std::cout << st.size() << std::endl << std::endl;
while (!st.empty()) {
int k;
st.top(k);
std::cout << k << std::endl;
st.pop();
}
std::cout << st.size() << std::endl << std::endl;
return 0;
}