---
title: "单向链表倒序操作"
author: "monkeycn"
date: "2011-05-16T22:27:31Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2011-05-16T22:27:31Z"
id: 1046274
url: "https://monkeycn.iteye.com/blog/1046274"
---

struct node
{
    int data;
    node* next;
};

// 单向链表头，如何倒序操作
inverse(node* head)
{
node thead; 
thead.next = NULL;
for(current = head; current!=null; )
{
     if ( current == head )
     {
	 node * t = current->next;
         thead.next = current;
	 current->next = NULL;
         current = t;    
     }
     else
     {
     	node * t = current->next;
        node* t2 = thead.next;

        thead.next = current;
        current->next = t2;         

        current = t;     
     }
}

return thead.next;

}