CCF GESP C++ 5级官方认证真题
2025年12月 GESP C++ 5级客观题真题与题解
本卷共收录 25 道考场原题(15 道单项选择题 + 10 道判断题)。下方展示前 3 道样题供预览,注册登录闯关平台即可解锁全卷 25 题、标准答案与防坑精讲!
单项选择题 · 试读样题 1/25
考点:链表结构、指针连接与操作复杂度
【单选 01】 对如下定义的循环单链表,横线处填写( )。
// 循环单链表的结点
struct Node {
int data; // 数据域
Node* next; // 指针域
Node(int d) : data(d), next(nullptr) {}
};
// 创建一个只有一个结点的循环单链表
Node* createList(int value) {
Node* head = new Node(value);
head->next = head;
return head;
}
// 在循环单链表尾部插入新结点
void insertTail(Node* head, int value) {
Node* p = head;
while (p->next != head) {
p = p->next;
}
Node* node = new Node(value);
node->next = head;
p->next = node;
}
// 遍历并输出循环单链表
void printList(Node* head) {
if (head == nullptr) return;
Node* p = head;
_______________________ //在此处填入代码
cout << endl;
}
-
A
01 while (p != nullptr){
02 cout << p->data << " ";
03 p = p->next;
04 }
```
-
B
01 while (p->next != nullptr){
02 cout << p->data << " ";
03 p = p->next;
04 }
```
-
C
01 do {
02 cout << p->data << " ";
03 p = p->next;
04 } while (p != head);
```
-
D
01 for(; p; p=p->next){
02 cout << p->data << " ";
03 }
```
单项选择题 · 试读样题 2/25
考点:链表结构、指针连接与操作复杂度
【单选 02】 区块链技术是比特币的基础。在区块链中,每个区块指向前一个区块,构成链式列表,新区块只能接在链尾,不允许在中间插入或删除。下面代码实现插入区块添加函数,则横线处填写( )。
//区块(节点)
struct Block {
int index; // 区块编号(高度)
string data; // 区块里保存的数据
Block* prev; // 指向前一个区块
Block(int idx, const string& d, Block* p) : index(idx), data(d), prev(p) {}
};
// 区块链
struct Blockchain {
Block* tail;
// 初始化
void init() {
tail = new Block(0, "Genesis Block", nullptr);
}
// 插入新区块
void addBlock(const string& data) {
_______________________ //在此处填入代码
}
// 释放内存
void clear() {
Block* cur = tail;
while (cur != nullptr) {
Block* p = cur->prev;
delete cur;
cur = p;
}
tail = nullptr;
}
};
-
A
01 Block* newBlock = new Block(tail->index + 1, data, tail);
02 tail = newBlock->prev;
```
-
B
01 Block* newBlock = new Block(tail->index + 1, data, tail);
02 tail = newBlock;
```
-
C
01 Block* newBlock = new Block(tail->index + 1, data, tail->prev);
02 tail = newBlock;
```
-
D
01 Block* newBlock = new Block(tail->index + 1, data, tail->prev);
02 tail = newBlock->prev;
```
单项选择题 · 试读样题 3/25
考点:链表结构、指针连接与操作复杂度
【单选 03】 下面关于单链表和双链表的描述中,正确的是( )。
struct DNode {
int data;
DNode* prev;
DNode* next;
};
// 在双链表中删除指定节点
void deleteNode(DNode* node) {
if (node->prev) {
node->prev->next = node->next;
}
if (node->next) {
node->next->prev = node->prev;
}
delete node;
}
struct SNode {
int data;
SNode* next;
};
// 在单链表中删除指定节点
void deleteSNode(SNode* head, SNode* node) {
SNode* prev = head;
while (prev->next != node) {
prev = prev->next;
}
prev->next = node->next;
delete node;
}
-
A
双链表删除指定节点是 $O(1)$,单链表是 $O(1)$
-
B
双链表删除指定节点是 $O(n)$,单链表是 $O(1)$
-
C
双链表删除指定节点是 $O(1)$,单链表是 $O(n)$
-
D
双链表删除指定节点是 $O(n)$,单链表是 $O(n)$
🔒
本卷剩余 22 道官方真题与全卷逐题精讲已封印
注册并登录 OI-Game 信奥闯关平台,即可按阶梯解锁 GESP 1~8 级共 108 套(2,700 道)历年真题、查看每道题的「秒杀锦囊 + 深度解析 + 防坑指南」,并将错题自动收录至个人专属错题本!