Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zoroxide/dynamic-stack-ds
https://github.com/zoroxide/dynamic-stack-ds
Last synced: about 9 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/zoroxide/dynamic-stack-ds
- Owner: zoroxide
- Created: 2024-06-08T15:26:47.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-06-08T18:53:41.000Z (5 months ago)
- Last Synced: 2024-06-09T17:14:59.561Z (5 months ago)
- Language: C
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dynamic Stacke Data Structure using C
### initializing
- ``` c++
#include
#include "dynamic_stack.h"int main() {
StackStatus_t status;// Create a stack with a maximum size of 5
struct Stack_t *myStack = CreateStack(5, &status);
if (status != STACK_OK) {
printf("Failed to create stack\n");
return -1;
}
return 0;
}
```
### Playground- ``` c++
// Push elements onto the stack
for (int i = 0; i < 5; ++i) {
int data = i;
status = PushStack(myStack, &data);
if (status != STACK_OK) {
printf("Failed to push data onto stack\n");
return -1;
}
}if (status == STACK_FULL) {
printf("Stack is full\n");
}// Pop elements from the stack
for (int i = 0; i < 5; ++i) {
const int *data = (int *)PopStack(myStack, &status);
if (status == STACK_OK) {
printf("Popped data: %d\n", *data);
} else {
printf("Failed to pop data from stack\n");
}
}// Check if the stack is empty
if (StackIsEmpty(myStack)) {
printf("Stack is empty\n");
}// Destroy the stack
DestroyStack(myStack, &status);if (status != STACK_OK) {
printf("Failed to destroy stack\n");
return -1;
}
```