当前位置: 首页>>代码示例>>C++>>正文


C++ MyStack::empty方法代码示例

本文整理汇总了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";

}
开发者ID:aszos,项目名称:SchoolWork,代码行数:28,代码来源:main.cpp

示例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";

}
开发者ID:aszos,项目名称:SchoolWork,代码行数:35,代码来源:main.cpp

示例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");
}
开发者ID:tiankonguse,项目名称:leetcode-solutions,代码行数:35,代码来源:implement-stack-using-queues.cpp

示例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;
}
开发者ID:beyondaymk,项目名称:ctci150,代码行数:16,代码来源:p0302.cpp

示例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";
}
开发者ID:shukerski,项目名称:oop-2013-14,代码行数:17,代码来源:main.cpp

示例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;
}
开发者ID:chenhch8,项目名称:data_structure,代码行数:20,代码来源:week4_1.cpp


注:本文中的MyStack::empty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。