1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > c语言字符就地逆置 高手看看我的C语言代码单链表实现就地逆置

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

时间:2020-07-12 06:49:52

相关推荐

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

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

单链表实现就地逆置#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;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。