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


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

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


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

示例1: 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

示例2: 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

示例3: 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

示例4:

void LinkedStack<T>::copy(LinkedStack<T> const& ls) {
	/* !!! неправилно !!!
	top = NULL;
	while(!ls.empty())
		push(ls.pop());
		*/
	if (ls.empty())
		top = NULL;
	else {
		// първа стъпка
		top = new StackElement<T>;
		top->data = ls.top->data;

		// подготовка за втората стъпка
		StackElement<T>* toCopy = ls.top->next;
		StackElement<T>* lastCopy = top;

		while (toCopy != NULL) {
			// копиране
			StackElement<T>* newCopy = new StackElement<T>;
			newCopy->data = toCopy->data;

			// завързване
			lastCopy->next = newCopy;

			// подготовка за следващата стъпка
			toCopy = toCopy->next;
			lastCopy = newCopy;
		}
		// затваряме веригата
		lastCopy->next = NULL;
	}
}
开发者ID:gvpavlov,项目名称:sdp-2014-15,代码行数:33,代码来源:lstack.cpp

示例5: 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

示例6: expressionMain

void expressionMain() {
    LinkedStack expressionNum;
    LinkedStack expressionOp;
    int choice = 1, num;
    string op, expression = "", numS;
    stringstream ss;
    cout << "Please enter your expression one character at a time." << endl;
    cout << "num:";
    num = enterNum();
    ss << num;
    ss >> numS;
    expression += numS;
    expressionNum.push(num);
    while (choice != 3) {
        switch (choice) {
            case 1: cout << "op:";
                    op = enterOp();
                    cout << "num:";
                    num = enterNum();
                    ss.clear();
                    ss << num;
                    ss >> numS;
                    expression += op + numS;
                    if (!expressionOp.empty() && opSize(expressionOp.top()) >= opSize(op)) {
                        eval(expressionOp,expressionNum);
                        if (!expressionOp.empty() && opSize(expressionOp.top()) >= opSize(op)) {
                            eval(expressionOp,expressionNum);
                        }
                        expressionOp.push(op);
                        expressionNum.push(num);
                    }
                    else {
                        expressionOp.push(op);
                        expressionNum.push(num);
                    }
                    cout << "Expression: " << expression << endl;
                    cout << "More(1),Quit(2)?: ";
                    cin >> choice;
                break;
            case 2: while (!expressionOp.empty())
                        eval(expressionOp,expressionNum);
                    cout << "Answer: " << expressionNum.top2() << endl;
                    choice = 3;
        }
    }
    
}
开发者ID:DaltheCow,项目名称:CIS-277,代码行数:47,代码来源:main.cpp

示例7: 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

示例8: isHtmlMatched

bool isHtmlMatched(const vector<string>& tags) {
  LinkedStack<string> S;
  typedef vector<string>::const_iterator Iter;

  for (Iter p = tags.begin(); p != tags.end(); ++p) {
    if (p->at(1) != '/')
      S.push(*p);
    else {
      if (S.empty()) return false;
      string open = S.top().substr(1);
      string close = p->substr(2);
      if (open.compare(close) != 0) return false;
      else S.pop();
    }
  }
  if (S.empty()) return true;
  else return false;
}
开发者ID:ingamelkerte,项目名称:GoodrichTamassiaCpp,代码行数:18,代码来源:matchHTML.cpp

示例9: horse_stack

void horse_stack(Point start, Point end) {
	LinkedStack<LinkedStack<Point> > history;
	LinkedStack<Point> startStack;
	ofstream clog("log.txt");
	startStack.push(start);
	history.push(startStack);
	while (!history.empty() &&
			(history.peek().empty() || history.peek().peek() != end)) {
		if (history.peek().empty()) {
			// Стъпка назад
			history.pop();
			if (!history.empty())
				history.peek().pop();
			clog << "Стъпка назад" << endl;
		}
		else {
			// стъпка напред
			Point current = history.peek().peek();
			clog << "Стъпка напред: " << current << endl;
			LinkedStack<Point> possibleMoves;
			board[current.first][current.second] = true;
			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(current.first + dx,
									   current.second + dy);
						if (inside_board(newstart)
							&&
							!board[newstart.first][newstart.second])
							possibleMoves.push(newstart);
					}
			LinkedStack<Point> pm(possibleMoves);
			clog << "---\n";
			printPath(pm,clog);
			clog << endl << "---\n";
			history.push(possibleMoves);
		}
	}
	if (!history.empty() && !history.peek().empty()) {
		cout << "Успех:\n";
		printHistory(history);
	}
}
开发者ID:triffon,项目名称:sdp-2015-16,代码行数:44,代码来源:horse.cpp

示例10: checkParentheses

bool checkParentheses(char const* s) {
	LinkedStack<char> stack;
	char const* p = s;
	while (*p != '\0') {
		switch (*p) {
		case '(':
		case '[':
		case '{':
		case '<':
			stack.push(*p);
			break;
		case ')':
		case ']':
		case '}':
		case '>':
			if (stack.empty() ||
				!matchParentheses(stack.pop(), *p))
				return false;
			break;
		}
		p++;
	}
	return stack.empty();
}
开发者ID:triffon,项目名称:sdp-2015-16,代码行数:24,代码来源:main.cpp

示例11: horse_queue

void horse_queue(Point start, Point end) {
	LinkedQueue<Position> q;
	q.enqueue(start);
	board[start.first][start.second] = true;
	Position current;
	LinkedStack<LinkedQueue<Position> > history;
	LinkedQueue<Position> level;
	int currentMove = 0;
	history.push(level);
	while (!q.empty() && (current = q.dequeue()).p != end) {
		if (current.move == currentMove) {
			history.peek().enqueue(current);
		} else {
			// current.move == currentMove + 1
			currentMove = current.move;
			LinkedQueue<Position> level;
			level.enqueue(current);
			history.push(level);
		}
		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(current.p.first + dx,
								   current.p.second + dy);
					Position newposition(newstart, current.move + 1);
					if (inside_board(newstart)
						&&
						!board[newstart.first][newstart.second]) {
						q.enqueue(newposition);
						clog << newposition << endl;
						board[newstart.first][newstart.second] = true;
					}

				}
	}
	// current == end -- успех
	// q.empty() -- неуспех
	clog << history;
	history.pop();
	if (current.p == end) {
		cout << "Успех за " << current.move << " хода!" << endl;
		LinkedStack<Point> path;
		path.push(current.p);
		while(!history.empty()) {
			// в history.peek() търсим първата позиция position,
			// за която isValidMove(current.p,position.p)
			Position position;
			while (!isValidMove(current.p,
					           (position = history.peek().dequeue()).p));
			// знаем, че isValidMove(current.p,position.p)
			// добавим position в пътя
			path.push(position.p);
			history.pop();
			current = position;
		}
		cout << path << endl;
	}
	else
		cout << "Неуспех!" << endl;
}
开发者ID:triffon,项目名称:sdp-2015-16,代码行数:61,代码来源:horse.cpp


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