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


C++ DLList::popBack方法代码示例

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


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

示例1: unittest2


//.........这里部分代码省略.........
		evaluate(list.getSize() == 6 && list.toString() == "5,10,20,30,50,55");
		cout << "Passed TEST 8: insert(20)/getSize/toString \n";
	} catch (MyException e) {
		cout << "# FAILED TEST 8: insert(20)/getSize/toString #\n";
	}
	
	list.insert(40);
	try {
		evaluate(list.getSize() == 7 && list.toString() == "5,10,20,30,40,50,55");
		cout << "Passed TEST 9: insert(40)/getSize/toString \n";
	} catch (MyException e) {
		cout << "# FAILED TEST 9: insert(40)/getSize/toString #\n";
	}
	
	list.insert(30);
	try {
		evaluate(list.getSize() == 8 && list.toString() == "5,10,20,30,30,40,50,55");
		cout << "Passed TEST 10: insert(30)/getSize/toString \n";
	} catch (MyException e) {
		cout << "# FAILED TEST 10: insert(30)/getSize/toString #\n";
	}
	
	list.insert(5);
	try {
		evaluate(list.getSize() == 9 && list.toString() == "5,5,10,20,30,30,40,50,55");
		cout << "Passed TEST 11: insert(5)/getSize/toString \n";
	} catch (MyException e) {
		cout << "# FAILED TEST 11: insert(5)/getSize/toString #\n";
	}
	
	try {
		evaluate(list.removeFirst(1) == false);
		cout << "Passed TEST 12: removeFirst(1) \n";
	} catch (MyException e) {
		cout << "# FAILED TEST 12: removeFirst(1) #\n";
	}
	
	try {
		evaluate(list.removeFirst(5) == true && list.getSize() == 8 && list.toString() == "5,10,20,30,30,40,50,55");
		cout << "Passed TEST 13: removeFirst(5)/getSize/toString \n";
	} catch (MyException e) {
		cout << "# FAILED TEST 13: removeFirst(5)/getSize/toString #\n";
	}
	
	try {
		evaluate(list.removeFirst(30) == true && list.getSize() == 7 && list.toString() == "5,10,20,30,40,50,55");
		cout << "Passed TEST 14: removeFirst(30)/getSize/toString \n";
	} catch (MyException e){
		cout << "# FAILED TEST 14: removeFirst(30)/getSize/toString #\n";
	}
	
	try {
		evaluate(list.removeFirst(30) == true && list.getSize() == 6 && list.toString() == "5,10,20,40,50,55");
		cout << "Passed TEST 15: removeFirst(30)/getSize/toString \n";
	} catch (MyException e){
		cout << "# FAILED TEST 15: removeFirst(30)/getSize/toString #\n";
	}
	
	try {
		evaluate(list.removeFirst(55) == true && list.getSize() == 5 && list.toString() == "5,10,20,40,50");
		cout << "Passed TEST 16: removeFirst(55)/getSize/toString \n";
	} catch (MyException e) {
		cout << "# FAILED TEST 16: removeFirst(55)/getSize/toString #\n";
	}
	
	try {
		evaluate(list.removeFirst(10) == true && list.getSize() == 4 && list.toString() == "5,20,40,50");
		cout << "Passed TEST 17: removeFirst(10)/getSize/toString \n";
	} catch (MyException e) {
		cout << "# FAILED TEST 17: removeFirst(10)/getSize/toString #\n";
	}
	
	list.popFront();
	try {
		evaluate(list.getSize() == 3 && list.toString() == "20,40,50");
		cout << "Passed TEST 18: removeHead/getSize/toString \n";
	} catch (MyException e) {
		cout << "# FAILED TEST 18: removeHead/getSize/toString #\n";
	}
	
	list.popBack();
	try {
		evaluate(list.getSize() == 2 && list.toString() == "20,40");
		cout << "Passed TEST 19: removeTail/getSize/toString \n";
	} catch (MyException e) {
		cout << "# FAILED TEST 19: removeTail/getSize/toString #\n";
	}
	
	list.clear();
	try {
		evaluate(list.getSize() == 0 && list.toString() == "");
		cout << "Passed TEST 20: clear/getSize/toString \n";
	} catch (MyException e) {
		cout << "# FAILED TEST 20: clear/getSize/toString #\n";
	}
	
	cout << "\nUNIT TEST COMPLETE\n\n";
	
	
}
开发者ID:CodeManiak,项目名称:dllist,代码行数:101,代码来源:unittest.cpp

示例2: processFile


//.........这里部分代码省略.........
                                cout << err << endl;
                            }
                        break;
                        
                        //if the character is T
                        case 'T':
                        
                            //if the list is empty
                            if (list->getSize() < 1) {
                                
                                //output failure to the console
                                cout << "LIST EMPTY" << endl;
                                
                            } else {
                                
                                //remove the Node at the head pointer and output success to the console
                                list->popFront();
                                cout << "REMOVED HEAD" << endl;
                            }
                        break;
                        
                        //if the character is K
                        case 'K':
                        
                            //if the list is empty
                            if (list->getSize() < 1) {
                                
                                //output failure to the console
                                cout << "LIST EMPTY" << endl;
                                
                            } else {
                                
                                //remove the Node at the tail pointer and output success to the console
                                list->popBack();
                                cout << "REMOVED TAIL" << endl;
                            }
                        break;
                        
                        //if the character is E
                        case 'E':
                        
                            //get the integer that follows the character
                            ss.str(nextLine.substr(2));
                            ss >> value;
                            
                            //attempt to remove all instances of Nodes with the integer value from the list
                            if (list->removeAll(value) == true) {
                                
                                //output success to the console
                                cout << "VALUE " << value << " ELIMINATED" << endl;
                                
                            } else {
                                
                                //output failure to the console
                                cout << "VALUE " << value << " NOT FOUND" << endl;
                            }
                            
                            //clear the stringstream
                            ss.clear();
                        break;
                        
                        //if the character is R
                        case 'R':
                        
                            //get the integer value that follows the character  
                            ss.str(nextLine.substr(2));
开发者ID:Svenzor84,项目名称:CSCI-21-FALL-2015,代码行数:67,代码来源:project3.cpp

示例3: main

int main(int argc, char *argv[])
{
    if(argc <= 1){
        cout << "Error: No command-line argument." << endl;
    }
    else{
        DLList<int> *intList = NULL;
	
    	ifstream fileIn(argv[1]);
    	
    	if(!fileIn.good()){
    	    cout << "Error: File could not be opened." << endl;
    	}
    	else{
    	    string line;
            while(getline(fileIn, line)){
                char operation = line[0];
                
                //cout << operation << " : ";
                
                if(operation == '#'){
                    //cout << "COMMENT" << endl;
                }
                else if(operation == 'C'){
                    cout << "LIST CREATED" << endl;
                    if(intList != NULL){
                        delete intList;
                    }
                    intList = new DLList<int>;
                }
                else if(intList == NULL){
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                }
                else{
                    if(operation == 'X'){
                        cout << "LIST CLEARED" << endl;
                        intList->clear();
                    }
                    else if(operation == 'D'){
                        cout << "LIST DELETED" << endl;
                        delete intList;
                        intList = NULL;
                    }
                    else if(operation == 'A'){
                        try{
                            cout << "VALUE " << intList->getFront() << " AT HEAD" << endl;
                        }
                        catch (string e){
                            cout << e << endl;
                        }
                    }
                    else if(operation == 'Z'){
                        try{
                            cout << "VALUE " << intList->getBack() << " AT TAIL" << endl;
                        }
                        catch (string e){
                            cout << e << endl;
                        }
                    }
                    else if(operation == 'T'){
                        if(intList->getSize() > 0){
                            intList->popFront();
                            cout << "REMOVED HEAD" << endl;
                        }
                        else{
                            cout << "LIST EMPTY" << endl;
                        }
                    }
                    else if(operation == 'K'){
                        if(intList->getSize() > 0){
                            intList->popBack();
                            cout << "REMOVED TAIL" << endl;
                        }
                        else{
                            cout << "LIST EMPTY" << endl;
                        }
                    }
                    else if(operation == 'N'){
                        cout << "LIST SIZE IS " << intList->getSize() << endl;
                    }
                    else if(operation == 'P'){
                        if(intList->getSize() > 0){
                            cout << *intList << endl;
                        }
                        else{
                            cout << "LIST EMPTY" << endl;
                        }
                    }
                    else{
                        string str = line.substr(2);
                        stringstream ss(str);
                        int value = 0;
                        ss >> value;
                        
                        if(operation == 'I'){
                            cout << "VALUE " << value << " INSERTED" << endl;
                            intList->insert(value);
                        }
                        else if(operation == 'F'){
                            cout << "VALUE " << value << " ADDED TO HEAD" << endl;
//.........这里部分代码省略.........
开发者ID:davidsides,项目名称:CSCI-21-SPRING-2014,代码行数:101,代码来源:proj3.cpp

示例4: processFile


//.........这里部分代码省略.........
                    ss.str(nextline.substr(2));
                    ss >> value;
                    list->pushFront(value);
                    cout << "VALUE " << value << " ADDED TO HEAD" << endl;
                }
                break;
            case 'B':
                if (list == NULL) {
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                } else {
                    ss.str(nextline.substr(2));
                    ss >> value;
                    list->pushBack(value);
                    cout << "VALUE " << value << " ADDED TO TAIL" << endl;
                }
                break;
            case 'A':
                if (list == NULL) {
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                } else {
                    try {
                        cout << "VALUE " << list->getFront() << " AT HEAD" << endl;
                    } catch (string e) {
                        cout << e << endl;
                    }
                }
                break;
            case 'Z':
                if (list == NULL) {
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                } else {
                    try {
                        cout << "VALUE " << list->getBack() << " AT TAIL" << endl;
                    } catch (string e) {
                        cout << e << endl;
                    }
                }
                break;
            case 'K':
                if (list == NULL) {
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                } else if (list->getSize() > 0) {
                    list->popBack();
                    cout << "REMOVED TAIL" << endl;
                } else {
                    cout << "LIST EMPTY" << endl;
                }
                break;
            case 'E':
                if (list == NULL) {
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                } else {
                    ss.str(nextline.substr(2));
                    ss >> value;
                    if (list->removeAll(value) == true) {
                        cout << "VALUE " << value << " ELIMINATED" << endl;
                    } else {
                        cout << "VALUE " << value << " NOT FOUND" << endl;
                    }
                }
                break;
            case 'R':
                if (list == NULL) {
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                } else {
                    ss.str(nextline.substr(2));
                    ss >> value;
                    if (list->removeFirst(value) == true) {
                        cout << "VALUE " << value << " REMOVED" << endl;
                    } else {
                        cout << "VALUE " << value << " NOT FOUND" << endl;
                    }
                }
                break;
            case 'G':
                ss.str(nextline.substr(2));
                ss >> value;
                if (list == NULL) {
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                } else if (list->get(value) == true) {
                    cout << "VALUE " << value << " FOUND" << endl;
                } else {
                    cout << "VALUE " << value << " NOT FOUND" << endl;
                }
                break;
            case 'N':
                if (list ==  NULL) {
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                } else {
                    cout << "LIST SIZE IS " << list->getSize() << endl;
                }
                break;
            default:
                break;

            }
        }
        inputstream.close();
    }
}
开发者ID:rkgilbert10,项目名称:CSCI-21-FALL-2015,代码行数:101,代码来源:Driver.cpp

示例5: run_project3


//.........这里部分代码省略.........
				try{
					btassert<bool>(list->getSize() != 0);
					cout << "VALUE " << list->getFront() << " AT HEAD" << endl;
				}
				catch (bool b){
					cout << "LIST EMPTY" << endl;
				}
			}
			
			//get the last element in the list if there is list.
			if(charLetter == "Z" && doesListExist == true){
				try{
					btassert<bool>(list->getSize() != 0);
					cout << "VALUE " << list->getBack() << " AT TAIL" << endl;
				}
				catch (bool b){
					cout << "LIST EMPTY" << endl;
				}
			}
	
	        //remove element from front of the list if there is a list.
			if(charLetter == "T" && doesListExist == true){
				if(list->getSize() == 0){
					cout << "LIST EMPTY" << endl;
				}
				else{
					list->popFront();
					cout << "REMOVED HEAD" << endl;
				}	
			}
			
			//remove element from back of the list if there is a list.
			if(charLetter == "K" && doesListExist == true){
				if(list->getSize() == 0){
					cout << "LIST EMPTY" << endl;
				}
				else{
					list->popBack();
					cout << "REMOVED TAIL" << endl;
				}
			}
			
			//get an element from the list if there is a list.
			if(charLetter == "G" && doesListExist == true){
				if(list->get(newNumber) == true){
					cout << "VALUE " << newNumber << " FOUND" << endl;
				}
				else{
					cout << "VALUE " << newNumber << " NOT FOUND" << endl;
				}
			}
			
			//eliminate all the same element, the element to be eliminate will be newNumber.
			if(charLetter == "E" && doesListExist == true){
				if(list->removeAll(newNumber) == true){
					cout <<"VALUE " << newNumber << " ELIMINATED" << endl;
				}
				else{
					cout << "VALUE " << newNumber << " NOT FOUND" << endl;
				}
			}

            //remove an element from the list, the element to be remove will be newNumber.
			if(charLetter == "R" && doesListExist == true){
				if(list->removeFirst(newNumber) == true){
					cout << "VALUE " << newNumber << " REMOVED" << endl;
				}
				else{
					cout << "VALUE " << newNumber << " NOT FOUND" << endl;
				}
			}

            //show number of element in the list.
			if(charLetter == "N" && doesListExist == true){
						cout << "LIST SIZE IS " << list->getSize() << endl;
			}

            //print the element(s) in the list.
			if(charLetter == "P" && doesListExist == true){
				if(list->getSize() == 0){
					cout << "LIST EMPTY" << endl;
				}
				else{
					cout << *list << endl;
				}
			}
			
			//display message if there is no list for an operation.
			if(doesListExist == false && charLetter != "#" && line != ""){
				cout << "MUST CREATE LIST INSTANCE" << endl;
			}
		}
		myfile.close();
		
		//delete the list if there is a list before exiting. NULL list pointer.
		if(doesListExist == true){
			delete list;
			list = NULL;
		}
	}
开发者ID:xmansyis,项目名称:CSCI-21-Spring-2014,代码行数:101,代码来源:p3.cpp

示例6: main

int main(int argc, char* argv[]) {

  DLList* list;
  stringstream ss;
  string strValue;
  int intValue;

  if (argc != 2) {
    cout << "USAGE: " << argv[0] << " FILENAME" << endl;

  } else {
    string currentLine;
    char input;
    cout << "PROCESSING FILE: " << argv[1] << endl;

    ifstream theFile(argv[1]);
    if (theFile.good()) {

      while (getline(theFile, currentLine)) {
        ss.clear();
        intValue = 0;
        strValue = "";
        bool activeList = false;

        input = currentLine.at(0);

          switch (input) {
            
            case 'C':
              if (activeList == false)
              list = new DLList;
              else if (activeList == true) {
              delete list; 
              list = new DLList; 
              }
              activeList = true;
              cout << "LIST CREATED" << endl;
              break;
              
            case 'X':
              list->clear();
              cout << "LIST CLEARED" << endl;
              break;

            case 'D':
              delete list;
              list = NULL;
              cout << "LIST DELETED" << endl;
              break;

             case 'I':
              strValue = currentLine.substr(2);
              ss << strValue;
              ss >> intValue;
              cout << "VALUE " << intValue << " INSERTED" << endl;
              list->insert(intValue);
              break;

            case 'F':
              strValue = currentLine.substr(2);
              ss << strValue;
              ss >> intValue;
              cout << "VALUE " << intValue << " ADDED TO HEAD" << endl;
              list->pushFront(intValue);
              break;

            case 'B':
              strValue = currentLine.substr(2);
              ss << strValue;
              ss >> intValue;
              cout << "VALUE " << intValue << " ADDED TO TAIL" << endl;
              list->pushBack(intValue);
              break;

            case 'A':
              cout << "VALUE " << list->getFront() << " AT HEAD" << endl;
              break;

            case 'Z':
              cout << "VALUE " << list->getBack() << " AT TAIL" << endl;
              break;

            case 'T':
              list->popFront();
              cout << "REMOVED HEAD" << endl;
              break;

            case 'K':
              list->popBack();
              cout << "REMOVED TAIL" << endl;
              break;

            case 'E':
              strValue = currentLine.substr(2);
              ss << strValue;
              ss >> intValue;
              if (list->removeAll(intValue))
                cout << "VALUE " << intValue << " ELIMINATED" << endl;
              else
                cout << "VALUE " << intValue << " NOT FOUND" << endl;
//.........这里部分代码省略.........
开发者ID:rickshere,项目名称:CSCI-21-SPRING-2014,代码行数:101,代码来源:Driver.cpp


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