diff --git a/TP3/List/BlockList.c b/TP3/List/BlockList.c index 1311e55..009da3f 100644 --- a/TP3/List/BlockList.c +++ b/TP3/List/BlockList.c @@ -63,6 +63,10 @@ void DeleteList(SList *list) SCell *GetCellFromBlock(SList *list) { SCell *pcell; + if ((pcell = GetCellFromRecycle(list))) + { + return pcell; + } while (!(pcell = _GetCellFromBlock(list->block))) { AddBlock(list->block); @@ -97,6 +101,16 @@ SCell *_GetCellFromBlock(SBlock *bList) return NULL; } +SCell *GetCellFromRecycle(SList *list) +{ + SCell *pcell = list->recycle; + if (pcell != NULL) + { + list->recycle = pcell->next; + } + return pcell; +} + SCell *AddElementBegin(SList *list, int data) { SCell *cell = GetCellFromBlock(list); diff --git a/TP3/List/BlockList.h b/TP3/List/BlockList.h index aa4fd0d..cec0716 100644 --- a/TP3/List/BlockList.h +++ b/TP3/List/BlockList.h @@ -16,7 +16,9 @@ SCell *AddElementEnd(SList *list, Data elem); SCell *AddElementAfter(SList *list, SCell *cell, Data elem); void DeleteCell(SList *list, SCell *cell); void PrintRecycleList(SList *list); -SCell* RecycleCell(SCell *, SCell *cell); +SCell *RecycleCell(SCell *head, SCell *cell); +SCell *GetCellFromBlock(SList *list); +SCell *GetCellFromRecycle(SList *list); SCell *GetFirstElement(SList *list); SCell *GetLastElement(SList *list); diff --git a/TP3/List/BlockMain.c b/TP3/List/BlockMain.c index ee5cccd..8979139 100644 --- a/TP3/List/BlockMain.c +++ b/TP3/List/BlockMain.c @@ -32,6 +32,11 @@ int main() PrintBlockList(list); PrintRecycleList(list); + AddElementEnd(list, 10); + PrintList(list); + PrintBlockList(list); + PrintRecycleList(list); + printf("\n"); // printf("Add 5, 3, 1\n"); diff --git a/TP3/List/a.out b/TP3/List/a.out index 92acb56..bee611a 100755 Binary files a/TP3/List/a.out and b/TP3/List/a.out differ