本文整理汇总了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
//.........这里部分代码省略.........