链表反转
来源:互联网 发布:如何避开公司网络监控 编辑:程序博客网 时间:2024/06/03 18:00
struct Node{ int x ; Node* next ;};Node* make_list(int n){ Node *head , *before , *now; if(n == 0) return NULL ; head = before = (Node *)malloc(sizeof(Node)) ; scanf("%d" , &head->x) ; head->next = NULL ; for(int i = 1 ; i < n ; i++){ now = (Node *)malloc(sizeof(Node)) ; scanf("%d" , &now->x) ; now->next = NULL ; before->next = now ; before = now ; } return head ;}Node * reverse_list(Node *head){ if(head == NULL) return NULL ; Node *reverse_head , * now , *nownext ,*before; now = head ; before = NULL ; while(now != NULL){ nownext = now->next ; if(nownext == NULL) reverse_head = now ; now->next = before ; before = now ; now = nownext ; } return reverse_head ;}void out_list(Node* head){ if(head == NULL){ puts("NULL") ; return ; } Node *now = head ; printf("%d" ,now->x) ; now = now->next ; while(now != NULL){ printf(" %d" , now->x) ; now = now->next ; } puts("") ;}int main(){ int n ; while(scanf("%d",&n)!=EOF){ Node* head = make_list(n) ; //out_list(head) ; Node* re_head = reverse_list(head) ; out_list(re_head) ; } return 0 ;}
0 0
- 链表反转
- 反转链表
- 单向链表反转
- 链表反转:
- 链表的反转
- 链表反转
- 反转单向链表
- 链表反转
- 单向链表反转
- 单向链表反转
- 链表的反转
- 链表反转
- 反转链表
- 链表反转
- 链表反转
- 链表反转
- 链表反转
- 链表的反转
- javaweb之Session客户端防表单重复提交(js)和服务端Session防表单重复提交
- “==” 、equals 、instance of区别
- Android版Web服务器实现(四)界面更新
- Minifilter驱动开发指南
- android 手指跟随拖拽 ACTION_MOVE 不能识别的问题
- 链表反转
- 虽然是技术人,但是要注重健康。so,第一篇讲养生 “治疗舒张压偏低”
- STL文件
- iOS开发之CGPoint、CGSize、CGRect、CGRectMake、window(窗口)、视图(view)
- decorators.xml的用法
- mysql 新建用户,授权,删除用户,修改密码
- 价值数十亿美元的创业公司,你知道几个?
- Oracle 数据字典 说明
- Learning Redis - 概念