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


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

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


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

示例1: part4test

bool part4test(){
  BinarySearchTree<BSTNode1<int>,int> part4;
  part4.add(20);
  part4.add(10);
  part4.add(30);
  part4.add(5);
  part4.add(15);
  part4.getLE(31);
  DLList<int> list =  part4.getLE(13);
  DLList<int> list2 =  part4.getLE(20);

  return (list.get(0)==5)&&(list.get(1)==10)&&
    (list2.get(0)==5)&&(list2.get(1)==10)&&(list2.get(2)==15)&&(list2.get(3)==20);
}
开发者ID:ShaverJT,项目名称:cse274d,代码行数:14,代码来源:test.cpp

示例2: testPart4

void testPart4(BinarySearchTree<BSTNode1<int>, int> *tree) {
	cout << "Testing Part 4..." << endl;
	cout << "______________________________" << endl;
	DLList<int> list = tree->getLE(10);
	cout << "All items in tree less than 10: ";
	for(int n = 1; n < list.size(); n++){
		cout << list.get(n) << ", ";
	}
	cout << endl;
}
开发者ID:ColeHoff7,项目名称:cse274d,代码行数:10,代码来源:test.cpp

示例3: unittest

void unittest ()
{
	cout << "\n  STARTING UNIT TEST!!!!!\n\n";
	
	DLList list;
	DLList list1;
	DLList list2;

	try {
		evaluate (list.getFront() == 0);
		cout << "Passed TEST 1: getFront '0' pushFront/getFront";
	} catch (MyException e) {
		cout << "#" << e.message << " TEST 1: getFront";
	}
	cout << endl;
	
	try {
		evaluate (list.getSize() == 0);
		cout << "Passed TEST 2: getSize '0' ";
	} catch (MyException e) {
		cout << "#" << e.message << " TEST 2: getSize";
	}
	cout << endl;
	
	try {
		evaluate (list.getBack() == 0);
		cout << "Passed TEST 3: getBack '0' ";
	} catch (MyException e) {
		cout << "#" << e.message << " TEST 3: getBack";
	}
	
	cout << "\n\n  FINISHED TESTING EMPTY LISTS!!!!!\n\n";
	
	list.pushFront(20);
	list.pushBack(5);
	list1.pushFront(63);
	list1.pushBack(12);
	list2.pushFront(14);
	list2.pushBack(99);	
	list.insert(44);
	list1.insert(87);
	list2.insert(56);
	
	try {
		evaluate (list.getFront() == 20);
		cout << "Passed TEST 4: getFront '20' pushFront/getFront ";
	} catch (MyException e) {
		cout << "#" << e.message << " TEST 4: getFront '20' pushFront/getFront";
	}
	cout << endl;
	
	try {
		evaluate (list1.getFront() == 63);
		cout << "Passed TEST 5: getFront '63' pushFront/getFront";
	} catch (MyException e) {
		cout << "#" << e.message << " TEST 5: getFront '63' pushFront/getFront";
	}
	cout << endl;
	
	cout << list2.getFront() << endl;
	try {
		evaluate (list2.getFront() == 14);
		cout << "Passed TEST 6: getFront '14' pushFront/getFront";
	} catch (MyException e) {
		cout << "#" << e.message << " TEST 6: getFront '14' pushFront/getFront";
	}
	cout << endl;
	
	try {
		evaluate (list.getBack() == 5);
		cout << "Passed TEST 7: getBack '5' pushBack/getBack";
	} catch (MyException e) {
		cout << "#" << e.message << " TEST 7: getBack '5' pushBack/getBack";
	}
	cout << endl;
	
	try {
		evaluate (list1.getBack() == 12);
		cout << "Passed TEST 8: getBack '12' pushBack/getBack";
	} catch (MyException e) {
		cout << "#" << e.message << " TEST 8: getBack '12' pushBack/getBack";
	}
	cout << endl;
	
	try {
		evaluate (list2.getBack() == 99);
		cout << "Passed TEST 9: getBack '99' pushBack/getBack";
	} catch (MyException e) {
		cout << "#" << e.message << " TEST 9: getBack '99' pushBack/getBack";
	}
	cout << endl;
	
	cout << "\n  FINISHED TESTING push/get-Back/Front!!!!!\n\n";
	
	try {
		evaluate (list.get(20) == true);
		cout << "Passed TEST 10: get '20' get(target)";
	} catch (MyException e) {
		cout << "#" << e.message << " TEST 10: get '20' get(target)";
	}
//.........这里部分代码省略.........
开发者ID:CodeManiak,项目名称:dllist,代码行数:101,代码来源:unittest.cpp

示例4: processFile

void processFile(char* filename) {
    
    //set up the input file stream and attempt to open the file
    ifstream fin;
    fin.open(filename);
    
    //if the file is successfully opened
    if (!fin.fail()) {
        
        //create a Doubly Linked List pointer (set to NULL)
        DLList* list = NULL;
        
        //set up reusable string stream object, int variable, and string nextLine
        stringstream ss;
        int value = 0;
        string nextLine;
        
        //while loop that continues until the end of the file is reached
        while (!fin.eof()){
            
            //get the next line from the file
            getline(fin, nextLine);
            
            //pull the first character from nextLine and make sure it is uppercase
            char firstCharacter = toupper(nextLine[0]);
            
            //if the character is C
            if (firstCharacter == 'C') {
                
                //if there is already a list, delete it first
                if (list != NULL) {
                    delete list;
                    list = NULL;
                }
                
                //create a new list and output success to the console
                list = new DLList;
                cout << "LIST CREATED" << endl;
                
            //if the first character is #
            } else if (firstCharacter == '#') {
                
                //do nothing
                
            } else {
                
                //any operation other than C requires a list instance
                //if there is no list instance
                if (list == NULL) {
                    
                    //output requirement to the console
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                    
                } else {
                    
                    //if there is a list instance perform an operation based on the first character of nextLine
                    switch(firstCharacter) {
                        
                        //if the character is X
                        case 'X':
                        
                            //clear the list and output success to the console
                            list->clear();
                            cout << "LIST CLEARED" << endl;
                        break;
                        
                        //if the character is D
                        case 'D':
                        
                            //delete the list, set the list pointer to NULL, and output success to the console
                            delete list;
                            list = NULL;
                            cout << "LIST DELETED" << endl;
                        break;
                        
                        //if the character is I
                        case 'I':
                        
                            //get the integer value that follows the character
                            ss.str(nextLine.substr(2));
                            ss >> value;
                            
                            //insert a Node into the list with the integer value from the input file as contents (ascending order)
                            list->insert(value);
                            
                            //output success to the console
                            cout << "VALUE " << value << " INSERTED" << endl;
                            
                            //clear the stringstream
                            ss.clear();
                        break;
                        
                        //if the character is F
                        case 'F':
                        
                            //get the integer that follows the character
                            ss.str(nextLine.substr(2));
                            ss >> value;
                            
                            //insert a Node at the head pointer with the value from the input file as contents
//.........这里部分代码省略.........
开发者ID:Svenzor84,项目名称:CSCI-21-FALL-2015,代码行数:101,代码来源:project3.cpp

示例5: 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

示例6: processFile

void processFile(string filename) {

    ifstream inputstream;
    DLList *list = NULL;
    inputstream.open(filename.c_str());

    if (inputstream.fail()) {
        cout << "Unable to open " << filename << " for processing." << endl;
    } else {
        string nextline;
        while (! inputstream.eof()) {

            stringstream ss;
            int value = 0;
            getline(inputstream, nextline);
            char firstCharacter = nextline[0];

            switch (toupper(firstCharacter)) {
            case 'C':
                if (list != NULL) {
                    delete list;
                }
                list = new DLList;
                cout << "LIST CREATED" << endl;
                break;
            case 'T':
                if (list == NULL) {
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                } else if (list->getSize() > 0) {
                    list->popFront();
                    cout << "REMOVED HEAD" << endl;
                } else {
                    cout << "LIST EMPTY" << endl;
                }
                break;
            case 'I':
                if (list == NULL) {
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                } else {
                    ss.str(nextline.substr(2));
                    ss >> value;
                    list->insert(value);
                    cout << "VALUE " << value << " INSERTED" << endl;
                }
                break;
            case 'P':
                if (list ==  NULL) {
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                } else if (list->getSize() > 0) {
                    cout << (*list) << endl;
                } else {
                    cout << "LIST EMPTY" << endl;
                }
                break;
            case 'X':
                if (list == NULL) {
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                } else {
                    list->clear();
                    cout << "LIST CLEARED" << endl;
                }
                break;
            case 'D':
                if (list == NULL) {
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                } else {
                    delete list;
                    list = NULL;
                    cout << "LIST DELETED" << endl;
                }
                break;
            case 'F':
                if (list == NULL) {
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                } else {
                    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;
                    }
//.........这里部分代码省略.........
开发者ID:rkgilbert10,项目名称:CSCI-21-FALL-2015,代码行数:101,代码来源:Driver.cpp

示例7: run_project3

void run_project3(string filename){

	ifstream myfile(filename.c_str());
    
	if (myfile.is_open()){
		string line;
		string charLetter;
		bool doesListExist = false;
		
		DLList* list;
        
		while (getline(myfile,line)){
			
			charLetter = line.at(0);
			line.erase(0,1);
			int newNumber = 0;
			stringstream converter(line);
			converter >> newNumber;
			
			//creating a list.
			if(charLetter == "C"){
				if(doesListExist == false){
					list = new DLList;
				}
				else if (doesListExist == true){
					delete list;
					list = new DLList;
				}
					
				cout << "LIST CREATED" << endl;
				doesListExist = true;
			}
	
	        //clear the list if there is a list.
			if(charLetter == "X" && doesListExist == true){
				list->clear();
				cout << "LIST CLEARED" << endl;
			}
			
			//delete the list if there is a list.
			if(charLetter == "D" && doesListExist == true){
				delete list;
				list = NULL;
				cout << "LIST DELETED" << endl;
				doesListExist = false;
			}
			
			//insert a newNumber into the list if there is list.
			if(charLetter == "I" && doesListExist == true){
				list->insert(newNumber);
				cout << "VALUE " << newNumber << " INSERTED" << endl;
			}
			
			//add a newNumber into the front of the list if there is list.
			if(charLetter == "F" && doesListExist == true){
				list->pushFront(newNumber);
				cout << "VALUE " << newNumber << " ADDED TO HEAD" << endl;
			}
			
			//insert a newNumber into the back of the list if there is list.
			if(charLetter == "B" && doesListExist == true){
				list->pushBack(newNumber);
				cout << "VALUE " << newNumber << " ADDED TO TAIL" << endl;
			}
			
			//get the first element in the list if there is list.
			if(charLetter == "A" && doesListExist == true){
				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){
//.........这里部分代码省略.........
开发者ID:xmansyis,项目名称:CSCI-21-Spring-2014,代码行数:101,代码来源:p3.cpp

示例8: 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

示例9: main

int main(){
  
  DLList<int> leven;
  for(int i = 0; i<30; i++){
    leven.add(i);
  }

  DLList<int> lodd = leven.deal();
  
  for(int i =0; i<leven.size(); i++){
    cout <<"entry "<< i << " of leven " << leven.get(i)<< endl;
  }
  for(int i =0; i<lodd.size(); i++){
    cout <<"entry "<< i << " of lodd " << lodd.get(i)<< endl;
  }
  
  
  DLList<int> lr;
  for(int i = 0; i<20; i++){
    lr.add(i);
  }

  for(int i =0; i<lr.size(); i++){
    cout <<"entry before rotate "<< i << " of lr " << lr.get(i)<< endl;
  }
  
  lr.Rotate(5);



  for(int i =0; i<lr.size(); i++){
    cout <<"entry after rotate "<< i << " of lr " << lr.get(i)<< endl;
  }
   


  
  DLList<int> l1;
  DLList<int> l2;
 
  l1.add(1);
  l1.add(2);
  l1.add(3);
  l1.add(4);
 
  l2.add(5);
  l2.add(6);
  l2.add(7);
  l2.add(8);

  cout<<"before absorb" << endl;

  for(int i =0; i<l1.size(); i++){
    cout <<"entry of l1 "<< i << " of l1 " << l1.get(i)<< endl;
  }

  for(int i =0; i<l2.size(); i++){
    cout <<"entry of l2 "<< i << " of l2 " << l2.get(i) <<endl;
  }
  
  l1.Absorb(l2);

  cout<<"after absorb" << endl;
  for(int i =0; i<l1.size(); i++){
    cout <<"entry of l1 "<< i << " of l1 " << l1.get(i)<< endl;
  }

  for(int i =0; i<l2.size(); i++){
    cout <<"entry of l2 "<< i << " of l2 " << l2.get(i) <<endl;
  }



   DLList<int> l;
  l.add(5);
  l.add(5);
  l.add(5);
  l.add(5);
 
  cout << "True " << l.IsPalindrome()<< endl;
 
  l.add(6);

  cout << "Now False " << l.IsPalindrome()<< endl;
  

}
开发者ID:ShaverJT,项目名称:cse274d,代码行数:87,代码来源:test.cpp


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