Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. // ConsoleApplication1.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6.  
  7. typedef struct Stack {
  8.     int* buf;
  9.     unsigned size;
  10.     unsigned t_ind;
  11. } Stack;
  12.  
  13. void create_stack(Stack* stack, unsigned size);
  14. void free_stack(Stack* stack);
  15.  
  16. void push(Stack* stack, int value);
  17. int pop(Stack* stack);
  18. int peek(Stack* stack);
  19.  
  20. int is_empty(Stack* stack);
  21. int is_full(Stack* stack);
  22.  
  23. void printstack(Stack* stack);
  24.  
  25. int main()
  26. {
  27.     Stack stack;
  28. //язь    ляляляляялял
  29.     return 0;
  30. }
  31. void create_stack(Stack* stack, unsigned size) {
  32.     stack->size = size;
  33.     stack->buf = (int*)malloc(size * sizeof(int));
  34.     stack->t_ind = 0;
  35.     return;
  36. }
  37.  
  38. void free_stack(Stack* stack) {
  39.     free(stack->buf);
  40.     return;
  41. }
  42.  
  43. void push(Stack* stack, int value) {
  44.     if (is_full(stack)) {
  45.         return;
  46.     }
  47.     stack->buf[(stack->t_ind)++] = value;
  48.     return;
  49. }
  50.  
  51. int pop(Stack* stack) {
  52.     if (is_empty(stack)) {
  53.         return 0;
  54.     }
  55.     return stack->buf[--(stack->t_ind)];
  56. }
  57. int peek(Stack* stack) {
  58.     return stack->buf[(stack->t_ind-1)];
  59. }
  60.  
  61. int is_empty(Stack* stack) {
  62.     return (stack->t_ind == 0);
  63. }
  64. int is_full(Stack* stack) {
  65.     return (stack->t_ind == stack->size);
  66. }
  67.  
  68. void printstack(Stack* stack) {
  69.     for (int i = 0; i < stack->t_ind; i++) {
  70.         printf("%4d", stack->buf[i]);
  71.     }
  72.     printf("\n");
  73.     return;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement