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


C++ Operation::getExpression方法代码示例

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


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

示例1: main

int main(int argc, char *argv[])
{
	ListContainer list_container;
	StackContainer stack_container;
	stack_container.all_lists = &list_container;
	TreeContainer tree_container;
	tree_container.all_lists = &list_container;
	HashContainer hash_container;
	hash_container.all_lists = &list_container;
	hash_container.stopword_tree = &tree_container;
	GraphContainer *graph_container[64];
	
	for(int i = 0; i<64; i++)
		graph_container[i] = NULL;

	if ( argc != 2 )
	{
		list_container.error("No file input or too many arguments, please try again");
		return -1;
	}
	ArgumentManager argMgr(argv[1]);
	string filename = argMgr.get("script");
	//string dict_filename = argMgr.get("dictionary");  

	char* fn = new char[filename.length()+1];
	strcpy(fn, filename.c_str());
	
	//list_container.initialize("dictionary", dict_filename); //insert the dictionary into a list
	//ListNode* dictionary_list = list_container.find_list("dictionary");
	//tree_container.initiate_tree(dictionary_list->list);
	//tree_container.printLevelOrder(tree_container.root, 6);
	
	
	ifstream fin(fn);
	if(fin.fail())
	{
		list_container.error("Failure to open script file "+filename+" exiting program...");
		return -1;
	}
	
	list_container.error("||||||||||||| Start log for script file "+filename+" |||||||||||||");
	
	OperationQueue opQueue(filename);
	
	while(!opQueue.isEmpty())
	{
		Operation op = opQueue.pop();
		//cout << op;
		if(op.isExpression())	//if true, operation is an expression that needs to be evaluated
		{
			stack_container.convertToPostfix(op.getExpression()); //convert infix to postfix
			stack_container.postfixCalc(op.getName()); //calculte the postfix expression and perform the operations
		}
		else if(op.getName() == "load" || op.getName() == "rank" || op.getName() == "dijkstra" || op.getName() == "topsort" )
		{
			if(op.getName() == "load") //loads a file-list text file into an object of graph_container, that is unique to the graph_container's web_id.
			{							//and then uses the objects initialize_graph function to build a graph based on the given file-list text file.
				string cleaned_filename = list_container.clean_file_name(op.getParameter(1));
				for(int i = 0; i<64; i++)//find the first empty graph_container. (support for up to 64 different load functions)
				{
					if(graph_container[i] == NULL) //once found, create an instance of the object, and initialize the graph with the given file list
					{
						graph_container[i] = new GraphContainer();
						graph_container[i]->web_id = op.getParameter(0);
						graph_container[i]->initialize_graph(cleaned_filename);
						break;
					}
				}
			}
			else if(op.getName() == "rank")
			{
				string cleaned_filename = list_container.clean_file_name(op.getParameter(1));
				for(int i = 0; i<64; i++)
				{
					if(op.getParameter(0) == graph_container[i]->web_id)
					{
						graph_container[i]->rank_output(cleaned_filename);
						break;
					}
				}
			}
			else if(op.getName() == "dijkstra")//call in script with dijkstra(WEBNAME,'vertexname.html')
			{
				string cleaned_filename = list_container.clean_file_name(op.getParameter(1));
				for(int i = 0; i<64; i++)
				{
					if(op.getParameter(0) == graph_container[i]->web_id)
					{
						graph_container[i]->dijkstra_calculate(cleaned_filename);
						break;
					}
				}
			}
		}
		else if(op.getName() == "write" || op.getName() == "read")			//if false, the operation could be a simple read or write
		{
			if(op.getName() == "write")
			{	
				if(op.parameterCount() == 2)	//this means there is no 'forward' or 'reverse' specification in which we will just assume forward
				{
//.........这里部分代码省略.........
开发者ID:smtheard,项目名称:Undergrad_Projects,代码行数:101,代码来源:pagerank.cpp

示例2: main

int main(int argc, char *argv[])
{
	ListContainer list_container;
	StackContainer stack_container;
	TimeComplexity time_complexity;				   //TODO: ensure that the below sharing of the same list_container does not interfere with the stack or arithmetic infix to postfix conversions.
	time_complexity.all_lists = &list_container; //gives the TimeComplexity object an address to the listContainer
	stack_container.all_lists = &list_container; //gives the stackContainer an address to the listContainer
/* 
	time_actual = 0;
	
	list_container.initialize("A", "A20.txt");
	ListNode* list = list_container.find_list("A");
	int n_hi = list_container.getN("A");
	int estimate = (n_hi*(6*n_hi))+ 9;
	cout << estimate << " ESTIMATE " << endl;
	list->list.alphabetize();
	cout << time_actual << endl;
	list->list.output();
	return 99; */
	if ( argc != 2 )
	{
		list_container.error("No file input or too many arguments, please try again");
		return -1;
	}
	ArgumentManager argMgr(argv[1]);
	string filename = argMgr.get("script");
	time_complexity.result_filename = argMgr.get("result");
	time_complexity.output("L1,L2,,,,-----,---,O(g(n)),--------,,", "");
	time_complexity.output("size,size,operation,T(n) estimate,T(n) actual,c,n0,g(n)=n^2", "append");
	
	char* fn = new char[filename.length()+1];
	strcpy(fn, filename.c_str());
	
	ifstream fin(fn);
	if(fin.fail())
	{
		list_container.error("Failure to open script file "+filename+" exiting program...");
		return -1;
	}
	
	list_container.error("||||||||||||| Start log for script file "+filename+" |||||||||||||");
	
	OperationQueue opQueue(filename);
	
	while(!opQueue.isEmpty())
	{
		Operation op = opQueue.pop();
		//cout << op << endl;
		if(op.isExpression())	//if true, operation is an expression that needs to be evaluated
		{
			stack_container.convertToPostfix(op.getExpression()); //convert infix to postfix
			stack_container.postfixCalc(op.getName()); //calculte the postfix expression and perform the operations
		}
		else if(op.getName() == "write" || op.getName() == "read")			//if false, the operation could be a simple read or write
		{
			if(op.getName() == "write")
			{	
				if(op.parameterCount() == 2)	//this means there is no 'forward' or 'reverse' specification in which we will just assume forward
				{
					list_container.writeForward(op.getParameter(0), op.getParameter(1));
				}
				else if(op.getParameter(2) == "forward")
				{
					list_container.writeForward(op.getParameter(0), op.getParameter(1));
				}
				else if(op.getParameter(2) == "reverse")
				{	
					list_container.writeReverse(op.getParameter(0), op.getParameter(1));
				}
				else
				{
					list_container.writeForward(op.getParameter(0), op.getParameter(1));
				}
				continue;
			}
			
			if(op.getName() == "read")
			{
				list_container.initialize(op.getParameter(0), op.getParameter(1));
				continue;
			}
		}
		else if(op.getName() == "union" || op.getName() == "intersection") //if not expression or read/write, it must be a union or intersection command
		{
			if(op.getName() == "union")
			{
				// call time complex func, and union here using op.getParameter(0) 1 and 2
				time_complexity.union_tracktime(op.getParameter(0), op.getParameter(1), op.getParameter(2));
				continue;
			}
			else if(op.getName() == "intersection")
			{
				// call time complex func, and intersection here using op.getParameter(0) 1 and 2
				time_complexity.intersection_tracktime(op.getParameter(0), op.getParameter(1), op.getParameter(2));
				continue;
			}
		}
		else
			list_container.error("operation is neither an expression, read/write, or union/intersection and therefore invalid");
	}
//.........这里部分代码省略.........
开发者ID:smtheard,项目名称:Undergrad_Projects,代码行数:101,代码来源:complexity.cpp


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