标签:temp source ret struct 介绍 span data head 遍历
这里介绍增加内存的方法来逆转。利用新内存,复制每个节点的数据,再将头指针的next指向新的头。如此循环遍历原链。
struct data{ data *next; int m_val; };
data* reverse(data *head){ data *new_chain == NULL; data *temp = NULL; while(head != NULL){ temp = (data*)malloc(sizeof(data)); //copy resource temp->m_val = head->m_val; if(new_chain == NULL){ new_chain = temp; }else{ temp->next=new_chain; new_chain = temp; }
head = head->next; } return new_chain; }
标签:temp source ret struct 介绍 span data head 遍历
原文地址:https://www.cnblogs.com/hustcpp/p/9160572.html