/*************************************************************************** * * * FUNCTION: CopyList * * * * PURPOSE: Create a Copy of an entire List. * * * * PARAMS: The list to copy; * * * * RETURN: A new list containing the copy if successful. * * NULL else. * * * * IMPORTS: TailList, NextList, InsertList * * * * NOTES: Because Lists contains only pointers only them are * * duplicated! The objects they refers are not copied. * * * * In LIFO and FIFO lists in head are the older elements, so * * if we insert in NewL from head to tail the object order * * is preserved. * * * * 10/11/92 Added for(i=0;... to manage circular Lists * * * ***************************************************************************/ List CopyList(List l) { List NewL; pointer object; if(!l) ErrorNULL("CopyList, not initialized List.\n"); NewL=(List)malloc(sizeof(struct Listtag)); NewL->objectsize=l->objectsize; NewL->nobject=0; NewL->H=NULL; NewL->T=NULL; NewL->C=NULL; NewL->EqualObj=l->EqualObj; NewL->CompareObj=l->CompareObj; NewL->type=l->type; NewL->hash=NULL; if(l->type!=CIRCULAR) { PushCurrList(l); for(HeadList(l);PrevList(&object,l);) InsertList(object, NewL); PopCurrList(l); } else { int i,n; n=l->nobject; PushCurrList(l); HeadList(l); for(i=0;i<n;i++) { PrevList(&object,l); InsertList(object, NewL); } PopCurrList(l); } return NewL; }
int AddNode(listPtr List, listnodePtr Node) { if (List == NULL) return LLIST_NULL; switch (List->Flags & LISTADDMASK) { case LISTADDCURR: return InsertList(List, Node); break; case LISTADDHEAD: return HeadList(List, Node); break; case LISTADDTAIL: return TailList(List, Node); break; case LISTADDSPLAY: return SplayInsertList(List, Node); break; default: return InsertList(List, Node); break; } return LLIST_ERROR; } /* AddNode() */
boolean oldMemberList(pointer object, List l) { pointer scanobj; ListElem *TempCurrList=l->C; if(l->hash) return MemberHash(object, l); TailList(l); while(NextList(&scanobj, l)) if(EqualObject(object, scanobj, l)) { if(!PrevList(&scanobj, l)) HeadList(l); return TRUE; } l->C=TempCurrList; return FALSE; }
boolean MemberList(pointer object, List l) /* 10/Nov/92 */ { pointer scanobj; ListElem *TempCurrList=l->C; int i,n; if(l->hash) return MemberHash(object, l); TailList(l); n=CountList(l); for(i=0;i<n;i++) { NextList(&scanobj, l); if(EqualObject(object, scanobj, l)) { if(!PrevList(&scanobj, l)) HeadList(l); /* Take a step back for */ return TRUE; /* right CurrList */ } } l->C=TempCurrList; return FALSE; }