单向循环链表
来源:互联网 发布:数据库管理dba 编辑:程序博客网 时间:2024/05/22 04:40
带头节点(指向头节点的指针header不能改变地址!!!)
每次输入数据都要重新找回最后一个节点,在输出数据时,要把最后一个节点的next指向null
#include <stdio.h>#include <stdlib.h>typedef struct link { int data; struct link* next;} node;void builddoublelink(node** header) { int data; printf("input data end with -1:\n"); scanf("%d", &data); node* new_node; while (data != -1) { if (*header == NULL) { new_node = (node*)malloc(sizeof(node)); new_node->data = data; *header = new_node; new_node->next = *header; } else { new_node = (node*)malloc(sizeof(node)); new_node->data = data; node* last_node = *header; while (last_node->next != *header) { last_node = last_node->next; } last_node->next = new_node; new_node->next = *header; } scanf("%d", &data); }}void print(node* header) { node* last_node = header; last_node = last_node->next; while (last_node->next != header) { last_node = last_node->next; } last_node->next = NULL; node* now_node = header; node* temp; while (now_node != NULL) { printf("%d ", now_node->data); temp = now_node; now_node = now_node->next; free(temp); }}int main(){ node* header = NULL; builddoublelink(&header); print(header); return 0;}
0 0
- 单向循环链表
- 单向循环链表
- 单向循环链表
- 单向循环链表
- 循环单向链表
- 单向循环链表
- 循环单向链表
- 单向链表循环
- 循环单向链表
- 单向循环链表
- 单向循环链表
- 单向循环链表
- 单向循环链表
- 单向循环链表
- 单向循环链表
- 单向循环链表反转
- 单向循环链表C++
- 单向不循环链表
- JSON解析(1)
- 【Hibernate系列】(一):心底好似旧相识
- 素材类网站 (欢迎补充)
- Java 多态详解 总结 以及 fina,abstractl关键字详解
- Android测试之Monkey
- 单向循环链表
- jQuery中的事件
- Linux中线程和进程的区别
- 深入分析JavaWeb Item40 -- 文件上传和下载
- Majority Element 找出一个数组中出现次数最多的元素
- ArcGIS Server:Service failed to start
- Python开发简单爬虫(二)
- CSDN blog第一文
- linux环境下实现svn服务器支持http协议