[Data Structure] Implementation of Static Links (C Language Description)

#include #include "stdlib.h"#define OK 1#define ERROR 0#define TRUE 1#define FALSE 0#define MAXSIZE 1000 // Define linear table Maximum capacity typedef int Status; typedef int ElemType; // Define the storage structure of the static linked list typedef struct{ ElemType data; // data field int curr; // store the index of the next node in the array} Node; // define the StaticLinkList typedef Node StaticLinkList[MAXSIZE] ;// First initialize a spare static table (actually an array) // L[0].curr = 1, L[1].curr = 2, L[2].curr = 3 .. .Status InitList(StaticLinkList L){ for(int i=0; i< MAXSIZE; i++){ L[i].curr = i+1;} // The current static linked list is empty, and the last element points to the next The index of an element is 0 (that is, it points to an element) L[MAXSIZE-1].curr = 0; return OK;}// Get the index of the free element and store the index in L[0].curr int GetBlankIndex(StaticLinkList L){ // L[0].curr always stores the index of free elements int blankIndex = L[0].curr; if (L[0].curr) L[0].curr = L[blankIndex].curr; return blankIndex;}Status ListInsert(StaticLinkList L, ElemType e){ int blankIndex = GetBlankIndex(L); L[blankIndex].data = e; return OK;}// Delete the i-th element Status ListDelete(StaticLinkList L, int i){ retu rn OK;}void Visit(StaticLinkList L){ int blankIndex = GetBlankIndex(L); for (int i = 1; i 

Leave a Comment

Your email address will not be published.