链式物理结构4
来源:互联网 发布:sql字符串中有' 编辑:程序博客网 时间:2024/05/18 04:11
/*
链式物理结构练习
*/
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int num;
struct node *p_next;
} node;
static node head, tail;
int main() {
int num = 0;
node *p_node = NULL;
head.p_next = &tail;
//按顺序把用户提供的整数插入到链中
do {
printf("请输入一个数字:");
scanf("%d", &num);
if (num >= 0) {
node *p_tmp = (node *)malloc(sizeof(node));
if (p_tmp) {
p_tmp->num = num;
p_tmp->p_next = NULL;
for (p_node = &head;p_node != &tail;p_node = p_node->p_next) {
node *p_first = p_node;
node *p_mid = p_first->p_next;
node *p_last = p_mid->p_next;
if (p_mid == &tail || p_mid->num > num) {
p_first->p_next = p_tmp;
p_tmp->p_next = p_mid;
break;
}
}
}
}
else {
break;
}
} while (1);
//打印链中所有数字
for (p_node = &head;p_node != &tail;p_node = p_node->p_next) {
node *p_first = p_node;
node *p_mid = p_first->p_next;
node *p_last = p_mid->p_next;
if (p_mid != &tail) {
printf("%d ", p_mid->num);
}
}
printf("\n");
//释放所有动态分配节点
while (head.p_next != &tail) {
node *p_first = &head;
node *p_mid = p_first->p_next;
node *p_last = p_mid->p_next;
p_first->p_next = p_last;
free(p_mid);
p_mid = NULL;
}
return 0;
}
链式物理结构练习
*/
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int num;
struct node *p_next;
} node;
static node head, tail;
int main() {
int num = 0;
node *p_node = NULL;
head.p_next = &tail;
//按顺序把用户提供的整数插入到链中
do {
printf("请输入一个数字:");
scanf("%d", &num);
if (num >= 0) {
node *p_tmp = (node *)malloc(sizeof(node));
if (p_tmp) {
p_tmp->num = num;
p_tmp->p_next = NULL;
for (p_node = &head;p_node != &tail;p_node = p_node->p_next) {
node *p_first = p_node;
node *p_mid = p_first->p_next;
node *p_last = p_mid->p_next;
if (p_mid == &tail || p_mid->num > num) {
p_first->p_next = p_tmp;
p_tmp->p_next = p_mid;
break;
}
}
}
}
else {
break;
}
} while (1);
//打印链中所有数字
for (p_node = &head;p_node != &tail;p_node = p_node->p_next) {
node *p_first = p_node;
node *p_mid = p_first->p_next;
node *p_last = p_mid->p_next;
if (p_mid != &tail) {
printf("%d ", p_mid->num);
}
}
printf("\n");
//释放所有动态分配节点
while (head.p_next != &tail) {
node *p_first = &head;
node *p_mid = p_first->p_next;
node *p_last = p_mid->p_next;
p_first->p_next = p_last;
free(p_mid);
p_mid = NULL;
}
return 0;
}
0 0
- 链式物理结构4
- 链式物理结构演示
- 链式物理结构2
- 链式物理结构3
- 【数据结构】单向线性链式物理结构list
- 7.28 链式物理存储结构的实现
- 链式物理结构(动态分配节点)
- Day16、文件拷贝、数据结构(逻辑结构、物理结构)顺序物理结构、链式物理结构
- 【C语言】从小到大插入新节点(链式物理结构)
- 【C语言】循环添加节点(链式物理结构)
- 链式物理结构(元素查找、元素删除、元素插入)
- 5.补发----数据的物理结构,线性结构与链式结构
- 【C语言】删除一个节点(仅一个)(单向物理链式结构)
- C++链式结构
- 线性表(链式结构)
- 栈 -- 链式存储结构
- 编程中的 链式 结构
- 指针和链式结构
- Restricting a Characteristic With Its Compounding Characteristic.
- 用sublime编译C++的方法
- POJ 3620 Avoid The Lakes(连通分量,DFS)
- Xcode分析
- 生成模型与判别模型
- 链式物理结构4
- 数独问题
- 高级工程师对PCB设计中的几点建议
- TCP/IP协议简介(三) 之 网络层
- Spring官方教程:使用WebSocket构建交互web应用
- 如何在Mac系统上安装Tomcat
- 网页UTF8转换GBK后出现问号"?"的原因
- ActiveMQ的知识总结
- js自学笔记--高级技巧