假定使用單鏈表。
簡單使用 reverse 函數即可。
typedef?int?elemcontent_t;typedef?struct?node_s?{
elemcontent_t?data; struct?node_s?*next;}?node_t,?*node_h;
node_h?reverse(?node_h?head?)?{
node_h?h?=?NULL; while?(?head?)?{node_h?next?=?head->next;
head->next?=?h;
h?=?head;
head?=?next;
} return?h;}
//?definition
node_h?first;
//?caller
first?=?reverse(?first?);