NTable.H.
#ifndef NTABL_H
#define NTABL_H
const int Tabl_Size 50
const int TableOk = 0;
const int TableEmpty = 1;
const int TableFull = 2;
extern int TablError;
typedef struct Element{
int data;
int key;
}
typedef struct Table {
int buf[Table_Size];
unsigned uk;
}
void InitTable (Table *T);
void PutTable (Table *T, Element E);
void OutTable (Table *T, element *E, int key);
int SearchKey(Table *T, int key);
int EmptyTabl (Table *T);
int FullTabl (Tabl *T);
#endif
NTable.C.
#include <stdio.h>
#include "NTable.h"
int TablError;
void InitTabl(Table *T)
{
T->uk = 0;
TablError = TableOk;
}
int SearchKey(Table *T, int key)
{
unsigned i;
for (i = 0; i < T->uk && T->buf[i].key != key;) { i++;}
if (i == T->uk) {
TableError = TableNoKey;
return -1;
}
return i;
}
void PutTable(Table *T, Element E)
{
if (FullTable(T)==1) { return;}
T->buf[T->uk] = E;
T->uk++;
}
void OutTable(Table *T, Element *E, int key)
{
if (EmptyTable(T)==1) {return; }
int posElement;
if ((posElement = SearchKey(T, key)) != -1)
{
E->date = T->buf[posElement].date;
E->key = T->buf[posElement].key;
if (posElement != T->uk - 1) {
T->buf[posElement] = T->buf[T->uk - 1];
}
T->uk--;
}
}
int EmptyTable(Table *T)
{
if (T->uk == 0) {
TableError = TableEmpty;
return 1;
}
return 0;
int FullTable(Table *T)
{
if (T->uk == Tabe_Size) {
TablError= TableFull;
return 1;
}
return 0;
}
Модуль таблицы как отображения на ОЛС:
TableList.H
#ifndef TABLE_LIST_H_
#define TABLE_LIST_H_
#include "list.h"
const intTableOk = 0;
const intTableNotMem = 1;
const intTableUnder = 3;
int extern TableError;
typedef struct Element {
int key;
int data;
} _Element;
typedef struct Table {
List *Buf;
unsigned n;
unsigned SizeBuf;
unsigned SizeEl;
};
void InitTable(Table *T, unsigned SizeBuf, unsigned SizeEl);
int EmptyTable(Table *T);
int PutTable(Table *T, BaseType E, func f);
int GetTable(Table *T, BaseType E, T_Key Key, func f);
int ReadTable(Table *T, BaseType E, T_Key Key, func f);
int WriteTable(Table *T, BaseType E, T_Key Key, func f);
void DoneTable(Table *T);
#endif