void LLS_DestroyStack(LinkedListStack* Stack) { while ( !LLS_IsEmpty(Stack) ) { Node* Popped = LLS_Pop( Stack ); LLS_DestroyNode(Popped); } /* 스택을 자유 저장소에서 해제 */ free(Stack); }
int main( void ) { int i = 0; int Count = 0; Node* Popped; LinkedListStack* Stack; LLS_CreateStack(&Stack); LLS_Push(Stack, LLS_CreateNode("abc")); LLS_Push(Stack, LLS_CreateNode("def")); LLS_Push(Stack, LLS_CreateNode("efg")); LLS_Push(Stack, LLS_CreateNode("hij")); Count = LLS_GetSize(Stack); printf("Size: %d, Top: %s\n\n", Count, LLS_Top(Stack)->Data); for (int i = 0; i < Count; i++) { if (LLS_IsEmpty(Stack)) { break; } Popped = LLS_Pop(Stack); printf("Popped: %s, ", Popped->Data); LLS_DestroyNode(Popped); if ( !LLS_IsEmpty(Stack)) { printf("Current Top: %s\n", LLS_Top(Stack)->Data); } else { printf("Stack Is Empty. \n"); } } LLS_DestroyStack(Stack); }