Design Pattern Examples
Overview of object-oriented design patterns
StackEntry Struct Reference

Represents an entry on a simple stack that wraps an "item" represented by an opaque pointer. More...

#include <stack.h>

Collaboration diagram for StackEntry:
Collaboration graph

Public Attributes

struct StackEntrynext
 Points to the next older entry in the stack.
 
void * item
 The item being held in this entry in the stack.
 

Detailed Description

Represents an entry on a simple stack that wraps an "item" represented by an opaque pointer.

This structure is allocated on the heap and then linked into the stack. The item is what is being pushed onto the stack, the StackEntry structure provides the necessary link to the next older StackEntry structure containing the next older item.

StackEntry* _undoStack = NULL;
void* item; // A pointer to something to be pushed onto the stack
Stack_Push(&_undoStack, item);
item = Stack_Pop(&_undoStack);
bool is_empty = Stack_IsEmpty(&_undoStack);
bool Stack_IsEmpty(StackEntry **stack)
Determines if the given stack is empty.
Definition: stack.c:82
void Stack_Push(StackEntry **stack, void *item)
Push the given entry onto the given stack.
Definition: stack.c:40
void * Stack_Pop(StackEntry **stack)
Pop the last entry from the given stack, returning the item.
Definition: stack.c:63
Represents an entry on a simple stack that wraps an "item" represented by an opaque pointer.
Definition: stack.h:32
void * item
The item being held in this entry in the stack.
Definition: stack.h:34

Definition at line 31 of file stack.h.

Member Data Documentation

◆ item

void* item

The item being held in this entry in the stack.

Definition at line 34 of file stack.h.

Referenced by Stack_Pop(), and StackEntry_Create().

◆ next

struct StackEntry* next

Points to the next older entry in the stack.

Definition at line 33 of file stack.h.

Referenced by Stack_Pop(), and Stack_Push().


The documentation for this struct was generated from the following file: