#include<iostream>

struct node{
  int payload;
  node* next;
};
void bianli(node* head){
  node* iterator = head;
  while(iterator){
    std::cout << iterator->payload<<" ";
    iterator = iterator->next;
  }
  std::cout<<" "<<std::endl;
}

node* diguifunc(node* head){
    if(head==nullptr|| head->next==nullptr)
        return head;
    
    node* second = head->next;
    node* new_head = diguifunc(second);
    second->next = head;
    head->next = nullptr;
    return new_head;
}

int main(){
    node* head = nullptr;
    for(int i=0;i<10;i++){
        node* new_node = new node;
        new_node->payload = i*10;
        new_node->next=head;
        head = new_node;
    }
    head = diguifunc(head);
    bianli(head);

    system("pause");
    return 0;
}

 

posted on 2016-08-19 02:17  新猪先生  阅读(311)  评论(0编辑  收藏  举报