mc王宁个人资料简介:数据结构编程1

来源:百度文库 编辑:中科新闻网 时间:2024/05/04 07:59:02
设顺序表a中的数据元素递增有序。试写一算法,将x插入到顺序表的适当位置上,以保持该表的有序性。
void InsertOrderList(SqList &a,ElenType x)
//已知顺序表a中的数据元素递增有序,将x插入到顺序表的适当位置上,
//以保持该表的有序性。

for(int i=0;i<length of the ordered list;i++)
{
if(item < a[i])
{
for(int j=i;j<length of..;j++)
{
int tmp=0;
tmp=a[i];
a[i]=item;
item=a[i];
}
break;
}
}