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


C++ Dlist::Rend方法代码示例

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


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

示例1: prompt


//.........这里部分代码省略.........
        }
      }
    } else if (sv[0] == "INSERT_BEFORE") {
      if (sv.size() != 3) {
        printf("INSERT_BEFORE s1 s2.\n");
      } else {
        if (words.find(sv[1]) != words.end()) {
          cout << sv[1] << " is already on the list\n";
        } else if (words.find(sv[2]) == words.end()) {
          cout << sv[2] << " is not on the list\n";
        } else {
          n = words[sv[2]];
          l->Insert_Before(sv[1], n);
          words[sv[1]] = n->blink;
        }
      }
    } else if (sv[0] == "INSERT_AFTER") {
      if (sv.size() != 3) {
        printf("INSERT_AFTER s1 s2.\n");
      } else {
        if (words.find(sv[1]) != words.end()) {
          cout << sv[1] << " is already on the list\n";
        } else if (words.find(sv[2]) == words.end()) {
          cout << sv[2] << " is not on the list\n";
        } else {
          n = words[sv[2]];
          l->Insert_After(sv[1], n);
          words[sv[1]] = n->flink;
        }
      }
    } else if (sv[0] == "PUSH_BACK") {
      if (sv.size() != 2) {
        printf("PUSH_BACK word.\n");
      } else {
        if (words.find(sv[1]) != words.end()) {
          cout << sv[1] << " is already on the list\n";
        } else {
          l->Push_Back(sv[1]);
          words[sv[1]] = l->Rbegin();
        }
      }
    } else if (sv[0] == "PUSH_FRONT") {
      if (sv.size() != 2) {
        printf("PUSH_FRONT word.\n");
      } else {
        if (words.find(sv[1]) != words.end()) {
          cout << sv[1] << " is already on the list\n";
        } else {
          l->Push_Front(sv[1]);
          words[sv[1]] = l->Begin();
        }
      }
    } else if (sv[0] == "POP_FRONT") {
      if (sv.size() != 1) {
        printf("POP_FRONT takes no arguments.\n");
      } else if (l->Empty()) {
        printf("POP_FRONT called on an empty list.\n");
      } else {
        s = l->Pop_Front();
        words.erase(words.find(s));
        cout << s << endl;
      }
    } else if (sv[0] == "POP_BACK") {
      if (sv.size() != 1) {
        printf("POP_BACK takes no arguments.\n");
      } else if (l->Empty()) {
        printf("POP_BACK called on an empty list.\n");
      } else {
        s = l->Pop_Back();
        words.erase(words.find(s));
        cout << s << endl;
      }
    } else if (sv[0] == "PRINT_FORWARD") {
      if (sv.size() != 1) {
        printf("PRINT_FORWARD takes no arguments.\n");
      } else {
        for (n = l->Begin(); n != l->End(); n = n->flink) {
          if (n != l->Begin()) cout << " ";
          cout << n->s;
        }
        cout << endl;
      }
    } else if (sv[0] == "QUIT") {
      exit(0);
    } else if (sv[0] == "PRINT_REVERSE") {
      if (sv.size() != 1) {
        printf("PRINT_REVERSE takes no arguments.\n");
      } else {
        for (n = l->Rbegin(); n != l->Rend(); n = n->blink) {
          if (n != l->Rbegin()) cout << " ";
          cout << n->s;
        }
        cout << endl;
      }
    } else {
      printf("Bad command\n");
    }
  }
  
}
开发者ID:sanluyene,项目名称:cs140,代码行数:101,代码来源:list_editor.cpp


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