有序数组的插入

 1 bool Insert( List L, ElementType X )
 2 {
 3     int i = 0;
 4     if(L->Last == MAXSIZE-1)    //元素已满,无法插入
 5         return false;
 6     
 7     for(; i <= L->Last; ++i)
 8     {
 9         if(X == L->Data[i])
10             return false;
11             
12         else if(X < L->Data[i])
13             continue;
14         else   //if(X > L->Data[i])
15         {
16             for(int j = L->Last + 1; j >= i+1; --j)  //把插入的位置之后的元素全部向后移动一个位置
17             {
18                 L->Data[j] = L->Data[j-1];
19             }
20             L->Data[i] = X;
21             ++L->Last;
22             return true;
23         }
24     }
25     L->Data[i] = X;    //X为最小值时,跳出循环
26     ++L->Last;
27     return true;
28 }
原文地址:https://www.cnblogs.com/FengZeng666/p/9712999.html