All pastes #735807 Raw Edit

Miscellany

public cpp v1 · immutable
·published 2007-10-13 23:37 UTC
rendered paste body
#include <string>#include <algorithm>class Implode{	public:		Implode(const std::string delim) : str(""), delim(delim);		void operator()(const std::string& s);		std::string getString() { return str; };	private:		std::string str;		std::string delim;}Implode::operator()(const std::string& s){	str += s + delim;}std::string infixToPostfix(const std::string& expr){	std::string::size_type p, q, r;	p = q = r = 0;	std::vector<string> numbers;	std::vector<string> operators;	// Find numbers	while(p != std::string::npos)	{		q = expr.find_first_of("0123456789.", p);		r = expr.find_first_not_of("0123456789.", q);		numbers.push_back(expr.substr(q,r-q));		q = expr.find_first_of("+-*/%", r);		operators.push_back(expr.substr(q,1));		p = q;	}	// Merge into string	Implode imp(" ");	for_each(numbers.begin(), numbers.end(), imp);	for_each(operators.begin(), operators.end(), imp);	return imp.getString();}