_______________________ c_list.h __________________
#ifndef c_list_h
#DEFINE C_LIST_H
#ifndef ERR
#define err -1
#define ok 1;
#ENDIF
#ifndef max
#define max 100
#define min 0
#ENDIF
Typedef int stat;
Typedef int Type;
Typedef struct ListItem {
Type Date; // Node Data
Struct ListItem * next; // Refers to the next node
} list_node; // Link table node
Typedef struct {
Struct ListItem * PTR; // Link Top Pointer
INT size; // Link surface length
} list; // Link list
List * list_init (void); // Initialization
STATUS LIST_DESTROY (List *); // Destroy
STATUS ADD_NODE (List *, const type); // Add a node
STATUS DELETE_ALL (List *); // Clear
Status delete_node (list *, list_node *); // Delete a node
Status INSERT_NODE (List *, const type); // Insert a node
List_node * find_node (const list *, const type); // Find
Status list_print (const list *); // Print
#ENDIF
--------- C_List.c ------------------
#include
#include
#include "c_list.h"
List * list_init (void)
{
List * p = (list *) malloc (sizeof (list));
IF (p == 0)
Return 0;
P-> PTR = 0;
P-> size = 0;
Return P;
}
Status List_Destroy (List * PEV)
{
IF (PEV == 0)
Return ERR;
Delete_all (PEV);
Free (pev);
Return OK;
}
Status add_node (list * p, const type date)
{
List_node * pev =
(List_node *) Malloc (sizeof (list_node));
IF (PEV == 0)
Return ERR;
PEV-> DATE = DATE;
PEV-> Next = P-> PTR;
P-> PTR = pev;
P-> Size ;
Return OK;
}
Status delete_node (List * p, list_node * pev)
{
List_node * temp = pev;
IF (PEV == 0)
Return ERR;
PEV = TEMP-> NEXT;
Free (TEMP);
P-> size -
Return OK;
}
Status Delete_all (List * PEV)
{
IX;
IF (PEV == 0)
Return ERR;
IF (pev-> size = 0)
Return ERR;
For (ix = 0; ix
Return OK;
}
Status INSERT_NODE (List * P, Const Type Date)
{
List_node * pev = p-> PTR;;
IF (p == 0)
Return ERR;
PEV = Find_Node (p, date);
IF (PEV == 0)
{
TYPE IA;
Printf ("Number / N of the input to be inserted);
Scanf ("% D", & IA);
Add_node (p, IA);
}
Else
{
TYPE IA;
List_node * pv =
(List_node *) Malloc (sizeof (list_node));
IF (PEV == 0)
Return ERR;
Printf ("Number / N of the input to be inserted);
Scanf ("% D", & IA);
PV-> DATE = IA;
PV-> Next = pev-> next;
PEV-> Next = PV;
P-> Size ;
}
Return OK;
}
List_node * find_node (const list * pev, const type date)
{
IX;
List_node * p = pev-> PTR;
For (ix = 0; ix
IF (P-> Date == Date)
Return P;
Else
P = P-> next;
Return 0;
}
Status List_Print (const list * pev)
{
IX;
List_node * p = pev-> PTR;
IF (PEV == 0)
Return ERR;
IF (pev-> size == 0)
Return OK;
For (ix = 0; ix
{
Printf ("% D / T", P-> Date);
P = P-> next;
}
Printf ("/ n");
Return OK;
}