C语言笔试题(8)——链表逆序
2012-03-27 22:13
309 查看
#include <stdio.h> #include <stdlib.h> struct node { int num; struct node *next; }; struct node *create_list(void) { struct node *head; head = (struct node *)malloc(sizeof(struct node)); head->next = NULL; return head; } void insert_list(struct node *head, int value) { struct node *p; p = (struct node *)malloc(sizeof(struct node)); p->num = value; p->next = head->next; head->next = p; return; } void printf_list(struct node *head) { struct node *p = head->next; while(p != NULL) { printf("%d\t", p->num); p = p->next; } printf("\n"); return; } int reverse_list(struct node *head) { struct node *p = head->next; struct node *q = head->next; if (head == NULL) return -1; head->next = NULL; while(p != NULL) { q = q->next; p->next = head->next; head->next = p; p = q; } return 0; } int main(void) { struct node *head; int i; head = create_list(); for(i = 10; i > 0; i--) { insert_list(head, i); } printf("Change before:\n"); printf_list(head); reverse_list(head); printf("Change later:\n"); printf_list(head); return 0; }
相关文章推荐
- c语言算法笔试(1)-------链表逆序
- C语言 逆序打印链表(递归)
- 练练手,练练手——C语言用递归对链表逆序
- 链表逆序的笔试题
- C语言实现链表的创建、增加、删除、查询、逆序、清空等基本操作
- ms的将链表逆序的笔试题
- 常见C语言面试题之九:链表逆序
- C语言 链表尾插入和逆序
- C语言链表在笔试面试中常考问题总结
- 【C语言】链表逆序
- C语言单链表逆序
- C语言 将链表中的元素在同一个链表中逆序输出
- 链表逆序的笔试题
- 链表的创建、测长、排序、插入、逆序的实现(C语言)
- 链表逆序在C语言中的技巧课程
- C语言 链表 数据结构实验之链表二:逆序建立链表
- C语言链表操作(新增单向链表的逆序建立)
- C语言实现哈希链表insert lookup函数 2012年中科蓝鲸笔试题
- 学习笔记——C语言实现单链表的基本操作:创建、输出、插入结点、删除结点、逆序链表
- 很简单的链表逆序C代码,笔试常考