forked from Raj217/Stack-in-C
-
Notifications
You must be signed in to change notification settings - Fork 2
/
stack.c
45 lines (42 loc) · 1.37 KB
/
stack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include "stack.h"
int main()
{
printf("For int:\n");
stack(int);
int_stack v;
int_stack_init(&v);
int_stack_push(&v, 5);
int_stack_push(&v, 10);
int_stack_push(&v, 15);
int_stack_push(&v, 20);
printf("Stack Size is: %lu \n", int_stack_size(&v));
printf("%d was popped\n", int_stack_top(&v));
printf("Stack Size is: %lu \n", int_stack_size(&v));
printf("Element at index 1 is: %d \n", int_stack_get(&v, 1));
printf("Stack top: %d \n", int_stack_top(&v));
int_stack_set(&v, 3, 34);
printf("Stack top: %d \n", int_stack_top(&v));
int_stack_pop(&v);
int_stack_pop(&v);
int_stack_pop(&v);
printf("Stack top: %c \n", int_stack_top(&v));
printf("\n---------------------------------\n\n");
printf("For char:\n");
stack(char);
char_stack v1;
char_stack_init(&v1);
char_stack_push(&v1, 'a');
char_stack_push(&v1, '$');
char_stack_push(&v1, '0');
printf("Stack Size is: %lu \n", char_stack_size(&v1));
printf("%c was popped\n", char_stack_top(&v1));
printf("Stack Size is: %lu \n", char_stack_size(&v1));
printf("Element at index 1 is: %c \n", char_stack_get(&v1, 1));
printf("Stack top: %c \n", char_stack_top(&v1));
char_stack_set(&v1, 2, '@');
printf("Stack top: %c \n", char_stack_top(&v1));
}