// Author Robinkin from Devonit .inc # ifndef Vector_C # Define Vector_C
#include "memory.c"
#define debug
#ifdef debug # include
#ifdef cmp // the list HAS SPECIAL CMP METHOD / / Two-way List Templates / / Template Function Declaration, Put in the Global Zone #define List_Declare (T) / / Struct List _ ## T ## _ node {/ t value; / list_ # #t ## _ node * next; / list _ ## t ## _ node * front; /}; / Struct List _ ## t {/ list _ ## t ## _ node * head; / list _ ## t ## _ node * tail ; / Int size; /}; / void list _ ## t ## _ new (list _ ## t & n) {/ n.Head = n.tail = null; / n.size = 0; / /} / / void List _ ## t ## _ del (list _ ## T & n) {/ list _ ## t ## _ node * h; / while (n.size! = 0) {/ h = n.head; / n.Head = H-> next; / free (h); / n.size--; /} /} / / bool list _ ## t ## _ push_back (list _ ## t & l, t x) {/ list _ ## t # #_node * node / = (list _ ## t ## _ node *) malloc (sizeof (list _ ## t ## _ node)); / if (null == node) {Return False;} / else {/ if (0 == L.SIZE) {/ L.HEAD = L. Tail = node; /} / node-> value = x; / node-> next = null; / node-> front = l.tail; / / /. Tail = node; / l.size ; / return true; /} /} / / bool list _ ## t ## _ push_front (list _ ## t & l, t x) {/ L IST _ ## t ## _ node * node / = (list _ ## t ## _ node *) malloc (sizeof (list _ ## t ## _ node)); / if (null == node) {Return False;} / else {/ If (0 == L.SIZE) {/ L.HEAD = L.Tail = node; /} / node-> value = x; /node = x; / node; / node-> front = NULL ; /L.HEAD=NODE; /L.SIZE ; / RETURN TRUE; /} /} / # undef CMP // Remove After Side Affect #ELSE // The List Has Plain CMP Method
// Two-way list template // Template function declaration, put in the global area #define list_declare (t) / struct list _ ## t ## _ node {/ t value; / list _ ## t ## _ node * next; / list _ ## T ## _ node * front; /}; / struct list _ ## t {/ list _ ## t ## _ node * head; / list _ ## t ## _ node * tail; / int size; /}; / void List_ # #t ## _ new (list _ ## T & n) {/ n.Head = n.tail = null; / n.size = 0; / /} / / void list _ ## t ## _ del (list _ ## t & n) {/ list _ ## t ## _ node * h; / while (n.size! = 0) {/ h = n.Head; / n.Head = H-> next; / free (h); / n.size--; /} /} / / bool list _ ## t ## _ push_back (list _ ## t & l, t x) {/ list _ ## t ## _ node * node / = (list _ ## t # # _Node *) Malloc (SizeOf (List _ ## T ## _ node)); / if (null == node) {Return False;} / else {/ if (0 == L.Size) {/ L.HEAD = L. Tail = node; /} / node-> value = x; / node-> next = null; / node-> front = l.tail; / / l.tail = node; / L.SIZE ; / return TRUE ; /} /} / / Bool list _ ## t ## _ push_front (list _ ## t & l, t x) {/ list _ ## t ## _ node * node / = (list _ ## t ## _ node *) malloc ( SizeOf (List _ ## t ## _ node)); / if (null == node) {Return False;} / else {/ if (0 == L.SIZE) {/ L.HEAD = l.tail = node; /} / Node-> value = x; /node->>Xt=L.Head; / node-> front = null; /l.Head=Node; /L.Size ; / return true; /} /} #ENDIF #define list_new (t, a) / list _ ## Ta; / list _ ## t ## _ new (a); // constructor
#define ln list_new
#define list_del (t, a) / list _ ## t ## _ del (a); // destructor
#define ld list_del
#ifdef debug
INT INT_CMP (INT A, INT B) {IF (a
IF (a> b) {RETURN 1;} if (a == b) {RETURN 1;}}
#define cmp int_cmp // Declare That the list/// Declared the CMP function to use this list // If there is no this define, this List uses ordinary <> = comparison method List_Declare (int)
Int main () {
List_new (int, a)
List_int_push_back (a, 1000); cout << a.tail-> value;
List_int_push_front (a, 100);
Cout << A.Head-> Value;
Cout << a.tail-> front-> value; cout << a.head-> next-> value;
List_del (int, a)
} #ENDIF
#ENDIF