Full Stack Implementation in C programming language


#include<stdio.h>
#include <stdbool.h>
#define max_size 100
int arr[max_size], top = -1;
bool isFull()
{
    if(top == (max_size - 1)){
        printf("Stack is Full!!\n");
        return true;
    }else{
        printf("Stack is Not Full!!!. You can insert Value!!\n");
        return false;
    }
}
bool isempty(){
    if(top == -1){
        return true;
    }else{
        return false;
    }
}
void push()
{
    if(isFull()){
        printf("Stack is Full!!\n");
    }else{
        int value;
        printf("Enter the value: ");
        scanf("%d", &value);
        top++;
        arr[top] = value;
        printf("%d is inserted into stack.\n", value);
    }
}
void pop()
{
    if(isempty()){
        printf("\nStack is Empty!!\n");
    }
    else{
        int value = arr[top];
        printf("%d is popped.\n", value);
        top = top - 1;
    }
}
void stack_size()
{
    printf("Size of the array is: %d.\n", top + 1);
}
void print_arr()
{
    printf("Array Elements are: ");
    for(int i = 0; i < (top + 1); i++){
        printf("%d ", arr[i]);
    }
    printf("\n\n");
}
int main()
{
    int n;
    while(1){
        printf("Press 1 for push 2 for pop 3 for array elements 4 for size: ");
        scanf("%d", &n);
        switch(n){
        case 1:
            push();
            break;
        case 2:
            pop();
            break;
        case 3:
            print_arr();
            break;
        case 4:
            stack_size();
            break;
        }
    }
    return 0;
}

2 comments:

  1. sauna supplies

    WAJA sauna is specialist manufacturer of top quality sauna products. Products include sauna rooms, steam rooms, barrel saunas, wooden hot tubs, and all kinds of sauna accessories.

    ReplyDelete
  2. Caesars Casino: Now Open | JamBase
    Welcome 제주 출장샵 to JamBase! Experience our newly 논산 출장마사지 opened casino in Murphy, 계룡 출장안마 North Carolina. 동두천 출장마사지 We are open 24/7. Casino is one of the largest 남원 출장샵 in North

    ReplyDelete