线性表(顺序表)的逆置(完整程序)
来源:互联网 发布:三端电容网络的变换 编辑:程序博客网 时间:2024/05/18 02:45
#include<stdio.h>#include<stdlib.h>#define OK 1#define ERROR -1#define MAX_SIZE 100typedef int Status;typedef int ElemType;typedef struct sqlist{ ElemType Elem_array[MAX_SIZE]; int length;}Sqlist;//插入运算void PrintList(Sqlist *L){ int i; for(i = 0;i<L->length;i++) { printf("%d\n",L->Elem_array[i]); }}Status CreatList(Sqlist *L){ int len; int i; //ElemType q; printf("请输入想要创建表的长度:"); scanf("%d",&len); if(len<0||len>MAX_SIZE) return ERROR; L->length = len; for(i = 0;i<len;i++) { scanf("%d",&L->Elem_array[i]); }}Status ReverseList(Sqlist *L){ int i; ElemType temp; if(L->length==0) { printf("表为空!\n"); return ERROR; } else { for(i = 0;i<L->length/2;i++) { temp = L->Elem_array[i]; L->Elem_array[i] = L->Elem_array[L->length-i-1]; L->Elem_array[L->length-i-1]=temp; } }}void main(){ Sqlist l; l.length = 0; //int l->Elem_array[MAX_SIZE]; //InsertElem(&l,1,2); //InsertElem(&l,2,2); //InsertElem(&l,3,2); CreatList(&l);printf("线性表的值如下:\n"); PrintList(&l); ReverseList(&l); printf("线性表逆置之后的值如下:\n"); PrintList(&l);}
上述程序运行结果如下:
我在编程序时犯的一个低级错误:
就是在交换数据时,写成了下面的程序:
L->Elem_array[i] = temp;temp = L->Elem_array[L->length-i-1];L->Elem_array[L->length-i-1] = L->Elem_array[i];
把交换顺序弄反了。
0 0
- 线性表(顺序表)的逆置(完整程序)
- 【数据结构】线性表的顺序存储完整程序
- 线性表的插入和创建(完整程序)
- 对顺序表的操作完整程序(1)
- 线性表的顺序存储实验程序
- 线性表的删除及查找定位删除(完整程序)
- 线性表线性(顺序)存储结构
- 线性表的顺序存储结构(顺序表)
- 数据结构--线性表的顺序表示(顺序表)
- 线性表的顺序储存(顺序表)
- 线性表的顺序存储(顺序表)
- 顺序表(完整操作)
- 线性表(顺序表)
- 顺序线性表(一)
- 对线性链表的完整操作(1)
- 线性表的完整操作
- 数据结构--线性链表(完整)
- 数据结构-线性表-顺序存储结构完整可执行代码
- 分类算法中的ROC与PR指标
- UNIX/Linux系统取证之信息采集案例
- A guide to Python's function decorators
- I.MX6Q(TQIMX6Q/TQE9)学习笔记——LTIB安装配置
- GitHub 排名前 100 的 Android 开源库简介-liusong001
- 线性表(顺序表)的逆置(完整程序)
- 雷军北大15分钟演讲:我至少有胆量去想
- Lambda表达式详解(例子详解)
- 关于查错
- OC 简化项目中拼接字符串的方法
- mysql事务
- 安卓打开远程调试
- 双目视觉三维重建
- 单片机 温度计