10_3.cpp
来自「本文档是(作者:钱能)《C++程序设计教程》课后习题答案。 选题编辑:张朝阳 」· C++ 代码 · 共 39 行
CPP
39 行
//10_3
#include <iostream.h>
struct Node{
char c;
Node* next;
};
Node* reverse(Node* head);
void main()
{
Node x[4];
for(int i=0; i<4; i++){
x[i].c='A'+i;
cout <<x[i].c <<"->";
x[i].next = &x[i+1];
}
cout <<"NULL" <<endl;
x[3].next = NULL;
Node* head = reverse(x);
for(Node* pH=head; pH; pH=pH->next)
cout <<pH->c <<"->";
cout <<"NULL" <<endl;
}
Node* reverse(Node* head)
{
Node* newHead=NULL;
for(Node* pT=head; pT; pT=head){
head=head->next;
pT->next = newHead;
newHead = pT;
}
return newHead;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?