(顺序有序表)插入元素
2014-07-27 10:05
246 查看
#include<stdio.h> typedef int A; const int LIST_INIT_SIZE=100; const int LISTINCRMENT=10; typedef struct { A *elem; int Length; int Listsize; int incrementsize; }SqList; void InitList(SqList &L,int maxsize=LIST_INIT_SIZE,int incresize=LISTINCRMENT) { L.elem=new A[maxsize]; L.Length=0; L.Listsize=maxsize; L.incrementsize=incresize; } void OrdInsert(SqList &L,A x) { int i; i=L.Length-1; while(i>=0&&x<L.elem[i]) //该是从小到大的输入而while(i>=0&&x>L.elem[i])则是从大到小的输入 { L.elem[i+1]=L.elem[i]; i--; } L.elem[i+1]=x; L.Length++; } int main() { int n,i; SqList L; InitList(L); scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&L.elem[i]); L.Length++; } for(i=0;i<n;i++) { printf("%d ",L.elem[i]); } printf("\n"); OrdInsert(L,4); for(i=0;i<n+1;i++) printf("%d ",L.elem[i]); return 0; }
相关文章推荐
- 设顺序表a中的数据元素递增有序,试设计一个算法,将x插入到顺序表的适当位置,以保持该表的有序性。
- 数据结构 2-11设顺序表va中的数据元素递增有序。试写一算法,将x插入到顺序表的适当位置上,以保持该表的有序性。
- 设顺序表va中的数据元素递增有序。试写一算法,将x插入到顺序表的适当位置上,以保持该表的有序性
- c语言:顺序表的实现(三)将元素e插入到一个递减有序表中,不改变顺序表的递减有序性。
- JavaScript 元素的插入顺序以及动态加载js
- 数据结构链表习题2.27,假设以两个元素依值递增有序排列的线性表A和B分别表示两个集合,现要求另辟空间构成一个顺序链表
- 1.有序顺序表的插入
- 线性表的顺序表 实现,及应用-----西文排序+前m个元素和后n个元素进行整体互换+构造纯集合+有序表求纯集合+循环有序链表表示两集合的并集
- <顺序表>从一个无序顺序表(也可以有序)中删除重复的元素,并使剩余元素间的相对次序保持不变
- 元素插入顺序表
- (1)顺序表的操作 ① 输入一组整型元素序列,建立线性表的顺序存储结构。 ② 实现该线性表的遍历。 ③ 在该顺序表中查找某一元素,查找成功显示查找元素,否则显示查找失败。 ④ 在该顺序表中删除或插入指
- 向有序数组中插入一个元素,使数组仍有序。
- 解决IE6中元素插入顺序造成的内存泄漏
- C语言:【动态顺序表】动态顺序表的在指定位置插入元素Insert,以及指定元素Find
- 简单顺序表的插入,删除,指定位置,指定元素的插入删除操作
- 在一个递增有序链表中插入新结点并保持链表递增顺序不变
- 在一个List的指定位置插入一个元素对这个List中的已有的元素顺序的影响
- 在有顺序的数列中插入一个元素后该数列仍然是有顺序的数组
- 6-2 有序顺序表的插入(10 分)
- 6-2 有序顺序表的插入