1-1 二叉排序树查找操作
BSTree SearchBST(BSTree T,ElemType e){
if(!T||T->data==e)return T;
else if(e<T->data)return SearchBST(T->lchild,e);
else
return SearchBST(T->rchild,e);
}
2-1 带头结点链栈的操作
Status Push(LinkList L,ElemType e)
{
struct LNode *p=(struct LNode*)malloc(sizeof(struct LNode));
p->data=e;
p->next=L->next;
L->next=p;
}
Status Pop(LinkList L,ElemType *e)
{
struct LNode *p;
if(L->next==NULL)
{
return -1;
}
p=L->next;
*e=p->data;
L->next=p->next;
free(p);
}
3-1 有序数组的插入
bool Insert( List L, ElementType X )
{
if(L -> Last + 1 == MAXSIZE)//满了
return false;
for (int i = 0; i <= L -> Last; i++ )
{
if (L -> Data[i] == X) //已经有了
return false;
else if (L -> Data[i] < X)
{
for (int j = L ->Last; j >= i; j -- )//i之后的后移一位
{
L -> Data[j + 1] = L -> Data[j];
}
L->Data[i] = X;
L->Last ++;
break;
}
else if (i==L->Last && L->Data[i]> X)//插在最后一位
{
L->Data[L->Last+1] = X;
L->Last ++;
break;
}
}
return true;
}