C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了反转单链表(C)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
/*反转单链表*/
#include<stdio.h> #include<stdlib.h> #define len sizeof(struct A) struct A { int num; struct A *next; }; int m; struct A *creat(int n)//创建结点个数为n的单链表 { struct A *head,*p1,*p2; m = 0; p1 = p2 = (struct A *)@H_421_13@malloc(len); scanf("%d",&p1->num); head = NULL; while (m < n) { m = m + 1; if (m == 1) { head = p1; } else { p2->next = p1; } p2 = p1; if (m < n) { p1 = (struct A*)@H_421_13@malloc(len); scanf("%d",&p1->num); } } p2->next = NULL; return head; } void print(struct A * head)//打印单链表 { struct A *p; p = head; if (head != NULL) { do { printf("%d ",p->num); p = p->next; } while (p != null); } } struct A* inverse(struct A* head)//反转单链表 { struct A *p1,*p2,*r; p2 = head; p1 = head->next; head->next = NULL; while (p1) { r = p1->next; p1->next = p2; p2 = p1; p1 = r; } head = p2; return head; } int main() { printf("输入链表中结点的数目:\n"); int n; scanf("%d",&n); printf("输入%d个结点:\n",n); struct A * head; head = creat(n); head=inverse(head); printf("输出链表中的结点:\n"); print(head); return 0; }

单链表反转CSDN博客

https://blog.csdn.net/feliciafay/article/details/6841115       反转过程非常清楚

大佬总结

以上是大佬教程为你收集整理的反转单链表(C)全部内容,希望文章能够帮你解决反转单链表(C)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。