#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; }
时间: 2024-10-20 06:13:29