Static one-way linked list

The necessary declaration

#include <stdio.h>
#include <stdlib.h>

#define MAXSIZE 1000

typedef int Status;
typedef int ElemType;


typedef struct
{
    ElemType data;
    int cur;
}component,SLinkList[MAXSIZE];

Find the location of e

Static list is empty when the direct return


The list is not empty and static and time varying e been looking for, find, or until the end

/**
 * 找到静态链表中第一个为e的元素的位置,若找到则返回位置i,否则返回0
 * i的值和data值同步,如果data满足等于e,则i的值就是data的索引,就返回该值,如果i==0,就说明到达末尾了。
 */
int LocateElem_SL(SLinkList S,ElemType e)
{
    int i = S[0].cur;   /* i指示表中第一个结点 */
    while(i && S[i].data != e)
        i = S[i].cur;
    return i;
}

Guess you like

Origin www.cnblogs.com/wjundong/p/11619841.html