void clear(List* list) { while ( list -> size_ !=0 ) { printf("%d", list -> size_); RemoveFront(list); } free(list->end_); }
void ClearList(List *list) { while (list->head != NULL){ RemoveFront(list); } list->crnt = NULL; }
int GSBuffer::Read( void * buffer,unsigned int len ) { unsigned int n=ReadCopyOut(buffer,len); RemoveFront(n); return n; }
int main(void) { Menu menu; List list; InitList(&list); do { Data x; switch (menu = SelectMenu()) { case InsFront: x = Read("先頭に挿入", NO | NAME); InsertFront(&list, x); break; case InsRear: x = Read("末尾に挿入", NO | NAME); InsertRear(&list, x); break; case RmvFront: RemoveFront(&list); break; case RmvRear: RemoveRear(&list); break; case PrintCrnt: PrintCrntNode(&list); break; case RmvCrnt: RemoveCrnt(&list); break; case SrchNo: x = Read("探索", NO); if (SearchNode(&list, x, NoEqual) != NULL){ PrintCrntNode(&list); } break; case SrchName: x = Read("探索", NAME); if(SearchNode(&list, x, NameEqual) != NULL){ PrintCrntNode(&list); } break; case PrintAll: PrintList(&list); break; case Clear: ClearList(&list); break; } } while (menu != Term); TermList(&list); return (0); }
void RemoveCrnt(List *list) { if (list->head != NULL){ if (list->crnt == list->head){ RemoveFront(list); }else{ Node *ptr = list->head; while (ptr->next != list->crnt){ ptr = ptr->next; } ptr->next = list->crnt->next; free(list->crnt); list->crnt = ptr; } } }
void RemoveRear(List *list) { if (list->head != NULL){ if((list->head)->next == NULL){ RemoveFront(list); }else{ Node *ptr = list->head; Node *pre; while (ptr->next != NULL){ pre = ptr; ptr = ptr->next; } pre->next = NULL; free(ptr); list->crnt = pre; } } }
void ClearDlist(Dlist *list) { while (!isEmptyDlist(list)){ RemoveFront(list); } }