// Source: dblist.cpp // Author: Michele Estebon // Date: 11/26/96 // For: CS1704: Introduction to Data Structures and Software Design // Last revision: 11/26/96 /************************************************************************************** Low Level Double linked list operations for pointer implementaion Provided functions: (public functions) ***************************************************************************************/ /*-- INCLUDES ------------------------------------------------------------------------*/ #include "dblist.h" #include "listglob.h" #include /*-- TYPE DEFINITIONS ----------------------------------------------------------------*/ // located in dblist.h //***************** LINKED LIST OPERATIONS ******************************************* void GetLabel( nodeptr List, labeltype& flabel) { if (List != null) strcpy(flabel, List->label); } void RefctDec( nodeptr& List ) { if (List != null) List->refct--; } void RefctInc( nodeptr& List) { if (List != null) List->refct++; } void GetCode( nodeptr List, codetype& fcode) { if (List != null) fcode = List->code; } void SetRefct( nodeptr& List, int ct) { if (List != null) List->refct = ct; } int GetRefct( nodeptr List ) { if (List!= null) return (List->refct); else return (-1); } void GetElements( nodeptr N, keytype &fname, labeltype &lbl, codetype &cde, int &refcount ) { strcpy(fname, N->name); strcpy(lbl, N->label); cde = N->code; refcount = N->refct; } void SetNextLink( nodeptr N, nodeptr A) { N->next = A; } void SetPrevLink( nodeptr N, nodeptr A ) { N->prev = A; } nodeptr GetNextLink( nodeptr N ) { return (N->next); } nodeptr GetPrevLink( nodeptr N) { return (N->prev); } void AssignItem( nodeptr N, keytype nuname, labeltype nulabel, codetype nucode ) { strcpy(N->name, nuname); strcpy(N->label, nulabel); N->code = nucode; } void AssignName( nodeptr N, keytype newname ) { strcpy( N->name, newname ); } void AssignLabel( nodeptr N, labeltype newlabel ) { strcpy( N->label, newlabel ); } void AssignCode( nodeptr N, codetype newcode ) { N->code = newcode; } void GetItem( nodeptr List, keytype& key1 ) { strcpy( key1, List->name); } void AllocateNew( nodeptr& newnode) { newnode = new node; SetPrevLink( newnode, NULL ); SetNextLink( newnode, NULL ); } void FreeNode( nodeptr oldnode ) { delete oldnode; } void InitList( void ) { // none needed for pointer implementation } Boolean GreaterThan( keytype key1, keytype key2) { // works for strings return ( strcmp(key1, key2) > 0 ); } Boolean EqualTo( keytype key1, keytype key2) { // works only for strings return ( strcmp( key1, key2) == 0 ); }