2017华工数据结构作业(已做)

2017华工数据结构作业

一、程序阅读填空

1. 在顺序表中第 i个位置插入新元素 x

template intSeqList::Insert (Type & x, inti){ if (i<0||i>last+1||last==MaxSize-1) return 0; //插入不成功 else {

last++;

__________ _data[j+1]=data[j]_ _________________;

}

1. 直接选择排序的算法

template void SelectSort(datalist& list) data[i] = x;

return 1; //插入成功 }

for( ________int j=MaxSize-1________________;j>i;j--)

{ for(inti=0; i

template viodSelectExchange(datalist& list, constinti){ int k = i;

for(int j=i+1;j

if(list.Vector[j].getKey()

___k=j__________________;//当前具有最小关键码的对象 if(k!=i) Swap(list.Vector[i], list.Vector[k]); //交换 }

3、 删去链表中除表头结点外的所有其他结点

template void List :: MakeEmpty ( ) { ListNode *q;

while (first→link!=NULL){

____________q=first->link______________;

_________fitst->link=q->link_________________; //将表头结点后第一个结点从链中摘下

delete q; //释放它 }

last = first; //修改表尾指针 }

4、基于有序顺序表的折半搜索递归算法(Element为有序顺序表) template intorderedList ::

BinarySearch(const Type & x, constint low, constint high)const {

int mid = -1;

if ( low< = high ) {

________mid=(low+high)/2__________________; if ( Element[mid].getKey( ) < x )

mid = BinarySearch (__________x,mid+1,high________________); else if ( Element[mid].getKey( ) > x ) mid = BinarySearch( x, low, mid -1 ); }

return mid; }

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4