习题3.15 自调整表Find例程

#include<stdio.h>

#include<stdlib.h>



typedef int * List;

/* 自调整表的Find数组实现 */

int

Find(List L,int MaxSize,int X)

{

    int where = 0;

    for( i = 1; i < MaxSize; i++ )

    {

        if( L[i] == X )

        {

            where = i;

            break;

        }

    }

    if(where){

        for( i = where; i > 1; i-- )

        {

            L[i] = L[i-1];

        }

        L[1] = X;

    }

    else

        return 0;

}

/* 自调整表的链表实现 */

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 0;

}
View Code

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

你可能感兴趣的:(find)