Welcome

C Programming Tutorial


C Data Structures - Stack Data Structure

   Stack is a Data Structure , Which Operates on one End. It follows Last-In-First-Out(LIFO) Principle. Items are added on top of another. In order to remove,lower level items, Items are stacked on top of another. In order to remove lower items, higher items or items above it, should be removed, first. then remove actual element. It operates on one end, all additions and deletions should be performed on that end.

In general, additions, deletions in stack, are called as push and pop respectively.
stack data structure implementation
 
     stack is used to solve
     tower of hanoi
     N queens problem
     infix to prefix conversion
  
  
#define BOTTOM 0
#define TOP 10  
  
struct  stack {
  
  	int value;
  	int buffer[10];
  	int top_pos;
  };
struct stack myStack;  
  void push(int value)
  {
  	if(top_pos < TOP)
	  	myStack.buffer[myStack.top_pos++]=value;
	
  	else printf("Stack is Full");
  }
  
  int pop()
  {
      if(top_pos < TOP && top_pos >=BOTTOM)
   	return buffer[myStack.top_pos--];
      printf("Stack is Empty");
  }
  
free(): double free detected in tcache 2

ADS