"stack in c" Code Answer's

You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "stack in c" answered properly. Developers are finding an appropriate answer about stack in c related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like stack in c. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on stack in c. 

stack in c 1

By Envious EagleEnvious Eagle on May 05, 2021
#include <stdio.h>

int MAXSIZE = 8;       
int stack[8];     
int top = -1;            

int isempty() {

   if(top == -1)
      return 1;
   else
      return 0;
}
   
int isfull() {

   if(top == MAXSIZE)
      return 1;
   else
      return 0;
}

int peek() {
   return stack[top];
}

int pop() {
   int data;
	
   if(!isempty()) {
      data = stack[top];
      top = top - 1;   
      return data;
   } else {
      printf("Could not retrieve data, Stack is empty.\n");
   }
}

int push(int data) {

   if(!isfull()) {
      top = top + 1;   
      stack[top] = data;
   } else {
      printf("Could not insert data, Stack is full.\n");
   }
}

int main() {
   // push items on to the stack 
   push(3);
   push(5);
   push(9);
   push(1);
   push(12);
   push(15);

   printf("Element at top of the stack: %d\n" ,peek());
   printf("Elements: \n");

   // print stack data 
   while(!isempty()) {
      int data = pop();
      printf("%d\n",data);
   }

   printf("Stack full: %s\n" , isfull()?"true":"false");
   printf("Stack empty: %s\n" , isempty()?"true":"false");
   
   return 0;
}

Source: www.codegrepper.com

Add Comment

0

All those coders who are working on the Whatever based application and are stuck on stack in c can get a collection of related answers to their query. Programmers need to enter their query on stack in c related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about stack in c for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of stack in c while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "stack in c". Visit this developer's friendly online web community, CodeProZone, and get your queries like stack in c resolved professionally and stay updated to the latest Whatever updates. 

Whatever answers related to "stack in c"

View All Whatever queries

Whatever queries related to "stack in c"

Browse Other Code Languages

CodeProZone