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


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

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


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

示例1: process_commands

// Function to read in lines of commands, parse, and execute them
void process_commands(){
	string line,cmd,subject,name;
	char type;
	int space=0;
	list<SimpleList<int> *> int_lists;
	list<SimpleList<double> *> double_lists;
	list<SimpleList<string> *> string_lists;
		
	while (getline(infile,line)){ // Read in line from input file
		outfile << "PROCESSING COMMAND: " << line << endl;
		space=line.find(" ");
		cmd = line.substr(0,space); // first argument of line
		line=line.substr(space+1);
		if (!cmd.compare("create")){
			space=line.find(" ");
			name=line.substr(0,space); // name of List to create
			line=line.substr(space+1); // line is now either queue or stack
			type=name[0]; // The data type of List: s, d, or i
			if (type=='i'){
				SimpleList<int> *n;
				try {
					// Try to find list, if list is found print out error
					find_list(int_lists,name);
 					outfile << "ERROR: This name already exists!" << endl;
				}
				// If list isnt found, exception is thrown and make new list
				catch (listDoesntExistException ){ 
					if (!line.compare("stack"))
						n=new Stack<int>(name);
					else if (!line.compare("queue"))
						n=new Queue<int>(name);
					int_lists.push_front(n);
				}
			}
			if (type=='d'){
				SimpleList<double> *n;
				try {
					// Try to find list, if list is found print out error
					find_list(double_lists,name);
					outfile << "ERROR: This name already exists!" << endl;
				}
				// If list isnt found, exception is thrown and make new list
				catch (listDoesntExistException ){
					if (!line.compare("stack"))
						n=new Stack<double>(name);
					else if (!line.compare("queue"))
						n=new Queue<double>(name);
					double_lists.push_front(n);
				}
			}
			if (type=='s'){
				SimpleList<string> *n;
				try {
					// Try to find list, if list is found print out error
					find_list(string_lists,name.c_str());
					outfile << "ERROR: This name already exists!" << endl;
				}
				// If list isnt found, exception is thrown and make new list
				catch (listDoesntExistException ){
					if (!line.compare("stack"))
						n=new Stack<string>(name);
					else if (!line.compare("queue"))
						n=new Queue<string>(name);
					string_lists.push_front(n);
				}
			}
		}
		try { // Look for list does not exist error in push or pop commands
			if (!cmd.compare("push")){
				space=line.find(" ");
				name=line.substr(0,space); // name of list to push to
				line=line.substr(space+1); // value to push
				type=name[0]; // type of list: s, d, or i
				if (type=='i'){
					SimpleList<int> *n;
					n=find_list(int_lists,name); // If list isnt found exception thrown and caught below
					n->push(atoi(line.c_str()));
				}
				if (type=='d'){
					SimpleList<double> *n;
					n=find_list(double_lists,name);
					n->push(atof(line.c_str()));
				}
				if (type=='s'){
					SimpleList<string> *n;
					n=find_list(string_lists,name);
					n->push(line);
				}
			}
			else if (!cmd.compare("pop")){
				try { // Look for list is empty error
					space=line.find(" ");
					name=line.substr(0,space); // name of list to pop from
					type=name[0]; // type of list: s, d, or i
					if (type=='i'){
						SimpleList<int> *n;
						int ret;
						n=find_list(int_lists,name);
						ret=n->pop(); // If list is empty, exception thrown and caught below
//.........这里部分代码省略.........
开发者ID:rgruener,项目名称:DSA1_ECE164,代码行数:101,代码来源:assgnment1.cpp


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