DeckListTwo.H
#ifndef _DECK_LIST_TWO_H_
#define _DECK_LIST_TWO_H_
#include "ListTwo.h"
const int DeckOk = listTwoOk;
const int DeckNoMem = listTwoNoMem;
const int DeckEmpty = listTwoEmpty;
extern int ListTwoError;
typedef listTwoBaseType BaseType;
typedef ListTwo Deck;
void InitDeck(Deck *D);
void PutDeckLeft(Deck *D, BaseType E);
void GetDeckLeft(Deck *D, BaseType *E);
void PutDeckRight(Deck *D, BaseType E);
void GetDeckRight(Deck *D, BaseType *E);
void DoneDeck(Deck *D);
int DeckEmpty(Deck *D);
#endif
DeckListTwo.C
#include<stdio.h>
#include "DeckListTwo.h"
void InitDeck(Deck *D) {
InitListTwo(D);
ListTwoError = DeckOk;
}
void PutDeckLeft(Deck *D, BaseType E)
{
BeginPtrListTwo(D);
PostPut(D, E);
ListTwoError = DeckEmpty;
}
void GetDeckLeft(Deck *D, BaseType *E)
{
BeginPtrListTwo(D);
PostGet(D, E);
ListTwoError = DeckNoMem;
}
void PutDeckRight(Deck *D, BaseType E)
{
EndPtrListTwo(D);
PredPut(D, E);
ListTwoError = DeckEmpty;
}
void GetDeckRight(Deck *D, BaseType *E)
{
EndPtrListTwo(D);
PredGet(D, E);
ListTwoError = DeckNoMem;
}
int DeckEmpty(Deck *D) {
return EmptyListTwo(D);
}
Модуль упорядоченной таблицы как отображения на массив:
Tablе.H
#ifndef TABL_H
#define TABL_H
const int Tabl_Size 50
const int TableOk = 0;
const int TableEmpty = 1;
const int TableFull = 2;
const int TableNoKey = 3;
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
Table.C
#include <stdio.h>
#include "Table.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;}
int posElement;
if ((posElement = SearchKey(T, E.key)) != -1) { T->buf[posElement].date = E.date; }
else {
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;
}
Модуль неупорядоченной таблицы как отображения на массив: