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


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

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


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

示例1: prompt

main(int argc, char **argv)
{
  map <string, Dnode *> words;
  Dlist *l;
  Dnode *n;
  vector <string> sv;
  string s;
  string p;

  if (argc != 2) {
    cerr << "usage: list_editor prompt(- for none)\n";
    exit(1);
  }

  l = new Dlist;
  p = argv[1];

  while(1) {
    if (p != "-") {
      printf("%s ", p.c_str());
      fflush(stdout);
    }
    if (!getline(cin, s)) exit(0);

    sv = StoSVec(s);
    if (sv.size() == 0 || sv[0][0] == '#') {
    } else if (sv[0] == "CLEAR") {
      if (sv.size() != 1) {
        printf("CLEAR takes no arguments.\n");
      } else {
        delete l;
        words.clear();
        l = new Dlist;
      }
    } else if (sv[0] == "EMPTY") {
      if (sv.size() != 1) {
        printf("EMPTY takes no arguments.\n");
      } else {
        cout << ((l->Empty()) ? "Yes" : "No") << endl;
      }
    } else if (sv[0] == "SIZE") {
      if (sv.size() != 1) {
        printf("SIZE takes no arguments.\n");
      } else {
        cout << l->Size() << endl;
      }
    } else if (sv[0] == "ERASE") {
      if (sv.size() != 2) {
        printf("ERASE word.\n");
      } else {
        if (words.find(sv[1]) == words.end()) {
          cout << sv[1] << " is not on the list\n";
        } else {
          l->Erase(words[sv[1]]); 
          words.erase(words.find(sv[1]));
        }
      }
    } 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 {
//.........这里部分代码省略.........
开发者ID:sanluyene,项目名称:cs140,代码行数:101,代码来源:list_editor.cpp


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