习题3.15 自调整表Find例程

时间:2023-03-09 19:07:14
习题3.15 自调整表Find例程
#include<stdio.h>
#include<stdlib.h> typedef int * List;
/* 自调整表的Find数组实现 */
int
Find(List L,int MaxSize,int X)
{
int where = ;
for( i = ; i < MaxSize; i++ )
{
if( L[i] == X )
{
where = i;
break;
}
}
if(where){
for( i = where; i > ; i-- )
{
L[i] = L[i-];
}
L[] = X;
}
else
return ;
}
/* 自调整表的链表实现 */
struct Node;
typedef struct Node * List;
struct Node{
int data;
struct Node *Next;
}; int
Find(int X,List L)
{
struct Node * p;
p = L->Next;
while(p != NULL && p->data != X )
p = p->Next;
if( p != NULL )
{
int t;
t = L->Next->data;
L->Next->data = X;
p->data = t;
}
else
return ;
}

标答第二个例程是把那个结点给删除,然后从新接在头结点后