Web Site under testing.....

STACK

  • Stack is an ordered collection of items and in c/c++ : array
  • Stack is an abstract data type which has it's own restrictions
  • Stack follows the concept of last in fist out(LIFO).
  • Stack has its own capacity i.e stack never has capacity of infinity. When we apply the rules of stack on Array it's comes out to be THE STACK.
  • Insetting and deleting of data from stack(Array) is only from one end called STACK TOP and stack is a dynamic, constantly changing object.

    Operations on Stack

  • Push:
    • When a data or item is added to the stack.
    • Always creates a memory address then perform Push operation.
  • Pop:
    • When a data or item is removed form the stack.
    • Always removes the memory address and then perform Pop operation.
  • Stack Top:
    • It is the data which currently pointed by stack pointer.
    • Stack pointer strore the memory address/structure of the LAST IN data.
  • Stack Underflow:
    • It is a property / statue / error for an empty stack.
    • It's is an error as stack pointer can not access item form empty stack.
    • If programmer initialized pointer to -1 by default, stack pointer will be -1 when stack is empty.
  • Stack Overflow:
    • It is a statue / result of push operation when stack is full.
    • Pointer value will be equal to the capacity of the stack
  • Stack Empty : Stack is in underflow condition.
  • Stack Full : Stack is in overflow condition.

Difference between Stack And Array

Stack:

  • Only one input
  • Fundamentally a dynamic object; whose size is constantly changing as items are popped and pushed.

Array:

  • Input can be multiple
  • Size of the array is fixed and user can not change to size

C++ code for Stair case

#include 
using namespace std;

int main() {
	int n;
	cout<<"Enter a number :";
	cin>>n;
	int k=1;
	for (int i=n; i >0; i--){

		for( int j=n-1; j>0; j--){
			cout<<" ";
		}
		for(int z=k; z>0; z--){
		cout<<"#";
		}
		k++;
		n--;
		cout<
                    
------ OUT PUT--------
Enter a number :6
     #
    ##
   ###
  ####
 #####
######
                    

Free Web Hosting