c语言字符就地逆置,高手看看我的C语言代码单链表实现就地逆置

高手看看我的C语言代码单链表实现就地逆置a1f0d32f23092fe37760042ce667abc5.png

单链表实现就地逆置#include #include struct type{ int date; struct type * next;}first;int main(){ struct type * opp(struct type * head);//定义算法 struct type * head=&first; struct type * p1=head; struct type * p2=NULL; first.date=0; for(int i=1; i<13; i++) { p2=(struct type *)malloc(sizeof(struct type)); p2->date=i*2+1; p1->next=p2; p1=p1->next; } p2->next=NULL; p1=NULL;//构造一个递增的单链表做实验 printf("单链表为\n"); p2=head; for(; p2->next!=NULL; p2=p2->next) { printf("%d ",p2->date); } printf("\n"); head=opp(head); p2=head; for(; p2->next!=NULL; p2=p2->next) { printf("%d ",p2->date); } printf("\n"); return 0;} struct type * opp(struct type * head){ struct type * pro=head; struct type * flag=head->next; struct type * next=flag->next; pro->next=NULL; for(; next->next!=NULL;) { flag->next=pro; pro=flag; flag=next; next=next->next; } next->next=flag; return next;}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值