本文整理汇总了C++中Dlist::Begin方法的典型用法代码示例。如果您正苦于以下问题:C++ Dlist::Begin方法的具体用法?C++ Dlist::Begin怎么用?C++ Dlist::Begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dlist
的用法示例。
在下文中一共展示了Dlist::Begin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
main()
{
string s;
Dlist l;
Dnode *d;
while (getline(cin, s)) l.Push_Front(s);
for (d = l.Begin(); d != l.End(); d = d->flink) cout << d->s << endl;
}
示例2: 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");
}
}
}