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


C++ LinkedStack::pop方法代码示例

本文整理汇总了C++中LinkedStack::pop方法的典型用法代码示例。如果您正苦于以下问题:C++ LinkedStack::pop方法的具体用法?C++ LinkedStack::pop怎么用?C++ LinkedStack::pop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LinkedStack的用法示例。


在下文中一共展示了LinkedStack::pop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: make_sum_bigger

void make_sum_bigger(int n, int m, LinkedStack<int>& x, LinkedStack<int>& y, LinkedStack<int>& z){
int data_f = 0;
  for(int i=0;i<m ;i++){                       //Събира двета числа до позицията на по-малко
    data_f += x.pop() + y.pop();               //
    if(data_f < 10){
        z.push(data_f);
        data_f = 0; }
    else {
        z.push(data_f%10);
        data_f = 1;
    }
}
    int result = data_f;                  // и прехвърля останалите цифри (+1 ако има едно на ум) от по-голямото число в стека с резултата
    while(!x.empty()){
    result += x.pop();
    if (result >= 10){
    z.push(result % 10);
    result = 1;
    }
    else {
    z.push(result);
    result = 0;
    }
}
}
开发者ID:smurfolan,项目名称:SDP-PCODE-REVIEW,代码行数:25,代码来源:main.cpp

示例2: make_sum_small

void make_sum_small(int n, int m, LinkedStack<int>& x, LinkedStack<int>& y, LinkedStack<int>& z){
  //81094: Confusing bracket alignment within this function.
  int data = 0;
  for(int i=0;i<n;i++){
    data += x.pop() + y.pop();
    if(data < 10){
        z.push(data);
        data = 0; }
    else {
        z.push(data%10);
        data = 1;
    }
}   int result = data;
    while(!y.empty()){
    result += y.pop();
    if (result >= 10){
    z.push(result % 10);
    result = 1;
    }
    else {
    z.push(result);
    result = 0;
    }
}
}
开发者ID:smurfolan,项目名称:SDP-PCODE-REVIEW,代码行数:25,代码来源:main.cpp

示例3: main

int main()
{ LinkedStack<int> numbers;
  try 
  { for (int i=10; i < 100; i+=10) numbers.push(i);
    while (!numbers.isEmpty()) cout << numbers.pop() << endl;
    numbers.pop();  
  }  
  catch(StackEmptyException e)
  {  cerr << e;
     return 1;
  }  
  return 0;    
}    
开发者ID:nkirov,项目名称:nkirov.github.com,代码行数:13,代码来源:LinkedStack.cpp

示例4: eval

void eval(LinkedStack& op, LinkedStack& num) {
    int numtop = num.top2();
    num.pop();
    if (op.top() == "+")
        numtop = add(num.top2(),numtop);
    else if (op.top() == "-")
        numtop = subtract(num.top2(),numtop);
    else if (op.top() == "*")
        numtop = multiply(num.top2(),numtop);
    else if (op.top() == "/")
        numtop = divide(num.top2(),numtop);
    op.pop(), num.pop();
    num.push(numtop);
}
开发者ID:DaltheCow,项目名称:CIS-277,代码行数:14,代码来源:main.cpp

示例5: main

int main() {

	LinkedStack<int> testLinkedStack;

	std::cout << "testLinkedStack.isEmpty() : " << testLinkedStack.isEmpty() << std::endl;
	std::cout << "testLinkedStack.getAllocatedSize() : " << testLinkedStack.getAllocatedSize() << std::endl;
	std::cout << "testLinkedStack.getSize() : " << testLinkedStack.getSize() << std::endl;

	testLinkedStack.push(5);
	testLinkedStack.push(6);
	testLinkedStack.push(7);
	testLinkedStack.push(9);
	testLinkedStack.push(10);

	std::cout << testLinkedStack.peek() << std::endl;

	int a = testLinkedStack.peek();
	testLinkedStack.pop();
	std::cout << a << std::endl;

	std::cout << testLinkedStack.peek() << std::endl;

	a = testLinkedStack.peek();
	testLinkedStack.pop();
	//testLinkedStack.pop(a);
	std::cout << a << std::endl;

	std::cout << testLinkedStack.peek() << std::endl;

	LinkedStack<int> testLinkedStack_2;
	testLinkedStack_2 = testLinkedStack;

	std::cout << testLinkedStack_2.peek() << std::endl;

	std::cout << "testLinkedStack.getSize() : " << testLinkedStack.getSize() << std::endl;

	testLinkedStack.clean();
	std::cout << "testLinkedStack.getSize() : " << testLinkedStack.getSize() << std::endl;
	std::cout << testLinkedStack.getAllocatedSize() << std::endl;

	testLinkedStack.push(5);
	testLinkedStack.push(6);
	std::cout << "testLinkedStack.getSize() : " << testLinkedStack.getSize() << std::endl;
	std::cout << testLinkedStack.peek() << std::endl;


	return 0;
}
开发者ID:pepincho,项目名称:Data-Structures-C-plus-plus,代码行数:48,代码来源:main.cpp

示例6: isBalanced

bool isBalanced(string brackets)		//O(N)
{
	LinkedStack bal = LinkedStack();
	int c1=0, c2=0, c3=0;
	string check;
	for(int i=0; i< brackets.size(); i++)
	{
		bal.push(brackets.substr(i,1));
	}
	
	for(int j=0; j<brackets.size(); j++)
	{
		check=bal.pop();
		if(check=="(") --c1;
		else if(check==")") ++c1;
		else if(check=="{") --c2;
		else if(check=="}") ++c2;
		else if(check=="[") --c3;
		else if(check=="]") ++c3;

		if(c1<0||c2<0||c3<0) return false;
	}
	//cout<<"c1: "<<c1<<" c2: "<<c2<<" c3: "<<c3<<endl;
	return (c1==0&&c2==0&&c3==0); 
}
开发者ID:samlee7,项目名称:DataStructures,代码行数:25,代码来源:smain.cpp

示例7: horse_rec

bool horse_rec(Point start, Point end,
			LinkedStack<Point>& path) {
	if (start == end) {
		path.push(end);
		cout << "Успех!" << endl;
		printPath(path);
		return true;
	}
	if (board[start.first][start.second])
		return false;
	board[start.first][start.second] = true;
	path.push(start);
	// !!! cout << start << endl;
	for(int dx = -2; dx <= 2; dx++)
		if (dx != 0)
			for(int sign = -1; sign <= 1; sign += 2) {
				int dy = sign * (3 - abs(dx));
				Point newstart(start.first + dx,
						       start.second + dy);
				if (inside_board(newstart) &&
					horse_rec(newstart, end, path))
					return true;

			}
	path.pop();
	return false;
}
开发者ID:triffon,项目名称:sdp-2015-16,代码行数:27,代码来源:horse.cpp

示例8: printHistory

void printHistory(LinkedStack<LinkedStack<Point> >& history, ostream& os = cout) {
	if (!history.empty()) {
		Point x = history.pop().peek();
		printHistory(history);
		os << x << endl;
	}
}
开发者ID:triffon,项目名称:sdp-2015-16,代码行数:7,代码来源:horse.cpp

示例9: make_sum

void make_sum(int n, int m, LinkedStack<int>& x, LinkedStack<int>& y, LinkedStack<int>& z){
//Kristian: Следващите 3 функции са напълно на 100% излишни. Можеше да използваш 2 stack-а и да направиш следното:
/*
int carryOver = 0;

while(!stack1.empty() || !stack2.empty()){
	int sum = stack1.top() + stack2.top() + carryOver;
	carryOver = sum/10 >= 0 ? 1 : 0;
	stack3.push(sum%10);
}

if(carryOver == 1)
	stack3.push(1);*/

if(n < m) {
        make_sum_small(n,m,x,y,z);           ///Първото число е по-голямо от второто
}
  else if (n > m){
        make_sum_bigger(n,m,x,y,z);       ///Второто число е по-голямо от първото
  }
 else {
       make_sum_equel(n,m,x,y,z);       ///Двете са равни
  }

    int p = 0;
    if (n>m)  p = n;
    else p = m;
    for(int i=0;i<p;i++){
    cout<<z.pop();
 }
}
开发者ID:smurfolan,项目名称:SDP-PCODE-REVIEW,代码行数:31,代码来源:main.cpp

示例10: printPath

void printPath(LinkedStack<Point>& path, ostream& os = cout) {
	if (!path.empty()) {
		Point x = path.pop();
		printPath(path, os);
		os << x << endl;
	}
}
开发者ID:triffon,项目名称:sdp-2015-16,代码行数:7,代码来源:horse.cpp

示例11: make_sum_equel

void  make_sum_equel(int n, int m, LinkedStack<int>& x, LinkedStack<int>& y, LinkedStack<int>& z){

    int data_s = 0;                            ///пази допълнителната еденица
      for(int i=0;i<m-1;i++){
    data_s += x.pop() + y.pop();
    if(data_s < 10) {
        z.push(data_s);
        data_s = 0; }
    else {
        z.push(data_s %10);
        data_s = 1;
    }
}
  data_s += x.pop() + y.pop();
  z.push(data_s);
}
开发者ID:smurfolan,项目名称:SDP-PCODE-REVIEW,代码行数:16,代码来源:main.cpp

示例12: testPointStack

void testPointStack() {
	LinkedStack<Point2D<int> > s;
	s.push(Point2D<int>(1, 2));
	s.push(Point2D<int>(2, 3));
	s.push(Point2D<int>(3, 4));
	while (!s.empty())
		cout << s.pop();
}
开发者ID:shukerski,项目名称:oop-2013-14,代码行数:8,代码来源:main.cpp

示例13: generate_numbers

void generate_numbers(int n, int m, LinkedStack<int>& first, LinkedStack<int>& second){
   int random_f, random_s;
   for (int i=0;i<n;i++){                   ///Представяне със свързан стек като всяка кутийка пази едноцифрено число
    if(i==0){
        random_f = rand() %9 + 1;
        first.push(random_f);
    }
    else {
        random_f = rand() %10;
        first.push(random_f);
    }
   }

    for (int i=0;i<m;i++){
    if(i==0){
        random_s = rand() %9 + 1;
        second.push(random_s);
    }
    else {
        random_s = rand() % 10;
        second.push(random_s);
    }
   }
LinkedStack<int> copy_of_first ;
LinkedStack<int> copy_of_second ;
LinkedStack<int> help = first;

 cout<<"First number: ";                   ///обръщане на стека, използвайки помощен стек
 for(int i=0; i<n; i++){
    copy_of_first.push(help.pop());
 }
 for(int i=0; i<n; i++){
    cout<<copy_of_first.pop();
 }
 cout<<endl;
 cout<<"Second number: ";
 help = second;
 for(int i=0; i<m; i++){
    copy_of_second.push(help.pop());
 }
 for(int i=0;i<m;i++){
    cout<<copy_of_second.pop();
 }
cout <<endl;
}
开发者ID:smurfolan,项目名称:SDP-PCODE-REVIEW,代码行数:45,代码来源:main.cpp

示例14: testStackTemplate

void testStackTemplate() {
	LinkedStack<double> ls;
	ls.push(1.8);
	cout << ls.pop() << endl;

	LinkedStack<Point2D<double> > sp;
	Point2D<double> p(1,2);
	sp.push(p);
}
开发者ID:triffon,项目名称:sdp-2015-16,代码行数:9,代码来源:main.cpp

示例15: is_balanced

bool is_balanced(string brackets)
{
  if(brackets == "") return true;
  LinkedStack ls;
  for (unsigned i = 0; i < brackets.size() ; i++)
  {
    string c = brackets.substr(i,i+1);
    if(c == "[" || c == "(" || c == "{")
    {
      ls.push(c);
    }
    else if(c == "]" )
    {
      if(ls.top() == "[")
      {
        ls.pop();
      }
      else return false;
    }
    else if(c == "}")
    {
      if(ls.top() == "{")
      {
        ls.pop();
      }
    }
    else if( c == ")" )
    {
      if(ls.top() == "(")
      {
        ls.pop();
      }
      else return false;
    }
    else 
    {
      if(ls.isEmpty()) return true;
    }
  }
  if(ls.isEmpty()) return true;
  return false;
}
开发者ID:sigmaxz,项目名称:data-structures,代码行数:42,代码来源:functions.cpp


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