轻松的编程学习
首页
题库
学习路径
在线商城
能力地图
下载应用
登录 / 注册
菜单
从尾巴往前数一遍
👁️ 1 人浏览
💬 0 人评论
❤️ 添加收藏
补全
count_back
:从 tail 出发倒着走完整条链,返回数到几个。
(本题用
g++ -std=c++17 -O0
编译。)
提交你的答案
请登录后提交答案。
去登录
← 把 prev 接上再从尾巴走回头
双向插入两个方向都接对 →
更多题目
改成"你好,有词"
输出"100 分"
把年龄改成 20
输出学习天数 30
修复:给文字加引号
修复:补上右括号
代码编辑器
语言:
python3
c11
cpp17
Ctrl
+
Enter
运行
👩🏫 AI
▶ 运行代码
重置代码
打印代码
#include <iostream> #include <string> #include <utility> #include <vector> using namespace std; struct DNode { string name; DNode* next = nullptr; DNode* prev = nullptr; }; pair<DNode*, DNode*> dbuild(const vector<string>& names) { DNode* head = nullptr; DNode* tail = nullptr; for (const string& x : names) { DNode* nd = new DNode{x}; if (head == nullptr) { head = nd; } else { tail->next = nd; nd->prev = tail; } tail = nd; } return {head, tail}; } int count_back(DNode* tail) { // TODO: 顺着 prev 一直走到 nullptr,边走边数 return -1; } int main() { auto [head, tail] = dbuild({"阿岚", "小满", "阿泰", "南风"}); cout << count_back(tail) << endl; }
本次输入:
输出:
👩🏫
AI
请登录后使用 AI 老师
×
登录后可获得解题思路、提示与错误分析。
去登录
关闭
🎉
恭喜你,回答正确!
系统判定:正确
我知道了
💬 题目评论
提交
全部评论
全部评论