10_3.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //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;
- }