10_3.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:

C#编程

开发平台:

Visual C++

  1. //10_3
  2. #include <iostream.h>
  3. struct Node{
  4.   char c;
  5.   Node* next;
  6. };
  7. Node* reverse(Node* head);
  8. void main()
  9. {
  10.   Node x[4];
  11.   for(int i=0; i<4; i++){
  12.     x[i].c='A'+i;
  13.     cout <<x[i].c <<"->";
  14.     x[i].next = &x[i+1];
  15.   }
  16.   cout <<"NULL" <<endl;
  17.   x[3].next = NULL;
  18.   Node* head = reverse(x);
  19.   for(Node* pH=head; pH; pH=pH->next)
  20.     cout <<pH->c <<"->";
  21.   cout <<"NULL" <<endl;
  22. }
  23. Node* reverse(Node* head)
  24. {
  25.   Node* newHead=NULL;
  26.   for(Node* pT=head; pT; pT=head){
  27.     head=head->next;
  28.     pT->next = newHead;
  29.     newHead = pT;
  30.   }
  31.   return newHead;
  32. }