Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
- //
- #include "pch.h"
- #include <iostream>
- typedef struct Stack {
- int* buf;
- unsigned size;
- unsigned t_ind;
- } Stack;
- void create_stack(Stack* stack, unsigned size);
- void free_stack(Stack* stack);
- void push(Stack* stack, int value);
- int pop(Stack* stack);
- int peek(Stack* stack);
- int is_empty(Stack* stack);
- int is_full(Stack* stack);
- void printstack(Stack* stack);
- int main()
- {
- Stack stack;
- //язь ляляляляялял
- return 0;
- }
- void create_stack(Stack* stack, unsigned size) {
- stack->size = size;
- stack->buf = (int*)malloc(size * sizeof(int));
- stack->t_ind = 0;
- return;
- }
- void free_stack(Stack* stack) {
- free(stack->buf);
- return;
- }
- void push(Stack* stack, int value) {
- if (is_full(stack)) {
- return;
- }
- stack->buf[(stack->t_ind)++] = value;
- return;
- }
- int pop(Stack* stack) {
- if (is_empty(stack)) {
- return 0;
- }
- return stack->buf[--(stack->t_ind)];
- }
- int peek(Stack* stack) {
- return stack->buf[(stack->t_ind-1)];
- }
- int is_empty(Stack* stack) {
- return (stack->t_ind == 0);
- }
- int is_full(Stack* stack) {
- return (stack->t_ind == stack->size);
- }
- void printstack(Stack* stack) {
- for (int i = 0; i < stack->t_ind; i++) {
- printf("%4d", stack->buf[i]);
- }
- printf("\n");
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement