posts - 124,  comments - 11,  views - 20万
< 2024年12月 >
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 1 2 3 4
5 6 7 8 9 10 11
复制代码
#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   新猪先生  阅读(312)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示