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


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

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


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

示例1: processFile

void processFile (string filename) {
    stringstream ss;
    int value = 0;
    DLList* list = NULL;
    char firstCharacter;
    ifstream fin(filename.c_str());
    if(!fin.fail()) {
        string nextline;
        while(!fin.eof()) {
            getline(fin, nextline);
            firstCharacter = nextline[0];
            switch(firstCharacter) {
            case '#':
                break;
            case 'C':
                if(list != NULL) { //if there was a previous list delete it
                    delete list;
                }
                else {
                    //creates a new list of type DLList
                    list = new DLList();
                    cout << "LIST CREATED" << endl;
                }
                break;
            case 'X':
                //if no list was created yet create list first
                if(list == NULL) {
                    cout << "MUST CREAT LIST INSTANCE" << endl;
                } //if there was a list clear it with the clear function
                else {
                    list->clear();
                    cout << "LIST CLEARED" << endl;
                }
                break;
            case 'D':
                //if there is a list deleted it
                if(list!= NULL) {
                    delete list;
                    cout << "LIST DELETED" << endl;
                }//if there isn't show warning
                else
                    cout << "MUST CREAT LIST INSTANCE" << endl;
                break;
            case 'I':
                if(list == NULL) {
                    cout << "MUST CREAT LIST INSTANCE" << endl;
                }
                else {
                    ss.str(nextline.substr(2));//gets the next whole value after the first value on a line
                    ss >> value;//puts the from input into an int
                    list->insert(value);//inserts the value into a node on the list
                    cout << "VALUE " << value << " INSERTED" << endl;
                    ss.clear();
                    ss.str("");
                }
                break;
            case 'F':
                ss.str(nextline.substr(2));
                ss >> value;
                list->insertHead(value);//inserts the value from input into the first node
                cout << "VALUE " << value << " ADDED TO HEAD" << endl;
                ss.clear();
                ss.str("");
                break;
            case 'B':
                ss.str(nextline.substr(2));
                ss >> value;
                list->insertTail(value);
                cout << "VALUE " << value << " ADDED TO TAIL" << endl;
                ss.clear();
                ss.str("");
                break;
            case 'A':
                if(list == NULL) {
                    cout << "VALUE NULL AT HEAD" << endl;
                }
                else {
                    list->getHead();
                    cout << "VALUE " << list->getHead() << " AT HEAD" << endl;
                }
                break;
            case 'Z':
                list->getTail();
                cout << "VALUE "  << list->getTail() << " AT TAIL" << endl;
                break;
            case 'T':
                if(list == NULL) {
                    cout << "MUST CREATE LIST INSTANCE" << endl;
                }
                else if (list->getSize() > 0) {
                    list->removeHead();
                    cout << "REMOVED HEAD" << endl;
                }
                else {
                    cout << "LIST EMPTY" << endl;

                }
                break;
            case 'K':
                if(list == NULL) {
//.........这里部分代码省略.........
开发者ID:jacobpicard,项目名称:csci21,代码行数:101,代码来源:processFile.cpp


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