This commit is contained in:
Oleksandr Vyshniakov 2025-10-12 21:17:39 +02:00
parent 603a764d2d
commit d08b36f4b8

View File

@ -12,12 +12,12 @@ struct stack{
struct stack* create_stack (int capacity) { struct stack* create_stack (int capacity) {
struct stack* s = malloc (sizeof(struct stack)); struct stack* s = malloc (sizeof(struct stack));
if (s==NULL) { if (s==NULL) {
printf("Error!"); printf("Error!\n");
exit(1); exit(1);
} }
s->values = malloc(capacity * sizeof(float)); s->values = malloc(capacity * sizeof(float));
if (s->values==NULL) { if (s->values==NULL) {
printf("Error!"); printf("Error!\n");
free(s); free(s);
exit(1); exit(1);
} }
@ -26,6 +26,32 @@ struct stack* create_stack (int capacity) {
return s; return s;
} }
void push_stack (struct stack* s, float value) {
if (s->size >= s->capacity) {
printf("Stack perepolnen!\n");
exit(1);
}
s->values[s->size] = value;
s->size++;
}
float pop_stack(struct stack* s) {
if (s->size <= 0) {
prinf("Erroe!\n");
exit(1);
}
s->size--;
return
}
void print_stack(struct stack* s) {
}
void destroy_stack (struct stack* s) {
}
int main() { int main() {
return 0; return 0;
} }