From 2b24db5b056fec7c9bd645703a1a6e737ab17e0d Mon Sep 17 00:00:00 2001 From: domitilacrispim Date: Tue, 30 Oct 2018 10:35:25 -0300 Subject: [PATCH] Add files via upload --- stack.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 stack.cpp diff --git a/stack.cpp b/stack.cpp new file mode 100644 index 0000000..2ba8dee --- /dev/null +++ b/stack.cpp @@ -0,0 +1,26 @@ +#include +int main (){ + int stack[100], op, top=0; + while(1){ + printf("Press 1 to insert, 2 to remove, 3 to see the lenght and any other number to exit!\n"); + printf("The stack supports until 100 elements.\n"); + scanf("%d", &op); + if(op==1) { + if(top==99){ + printf("The stack is full!\n"); continue; + } + + printf("Type an integer!\n"); + scanf("%d", &op); + stack[top]=op; + top++; + continue; + } + else if(op==2){ + if(top==0) { printf("The stack is empty!\n"); continue;} + printf("Removed : %d \n " , stack[--top]); + } + else if (op==3) printf("%d\n", top); + else return 0; + } +}