Skip to main content

Definition of Stack and its algorithm with working process(data structure)



                 Stack                     
  A Stack is an ordered collection of items where the addition of items and the removal of existing items always takes place at the same end. This end is commonly referred to as the “top".

* working method of stack :-

i> Initially top=-1
ii> By increasing top pointer we can insert element    in the stack.
iii> when top=size of stack-1  then stack is full.
iv> By decreasing the top pointer we can remove   the   element from stack.
v> when top=-1 then the stack is empty.



figure shows run time stack








* The fundamental operations which are possible on a stack are:-
    
   1. push operation (insertion).
   2. pop operation (deletion).
   3. peep opetation(extract information).
  4. update operation (change value at any position).

1. push operation:-
 In case of stack Insertion of any item in stack is called push. In stack any item is inserted from top of the stack, When you insert any item in stack top will be increased by 1.
push operation in stack

* Algorithm for insertion (push operation):-

 Step1: [Check for stack overflow]
             If  top>= size of stack  then
             output:- " stack is overflow "  and exit.

Step 2: [Incriment the pointer value by 1 ]
             top=top+1

Step 3: [perform the insertion operation ]
             S[top] = value.       (here S is array name)

step 4: Exit.


2. pop operation:-
  In case of stack deletion of any item from stack is called pop. In any item is delete from top of the stack, When you delete any item from stack top will be decreased by 1.

pop operation in stack


* Algorithm for deletion (pop operation ):-

Step 1: [Check for stack underflow]
            If top=0  then
            output:- "Stack is underflow "  and exit.

step 2: [Removing the top valve ]
            value = S[top].      

step 3: [decrementing the pointer value by 1 ]
           top = top-1

Step 4: [Return the formal information os the stack ]
             return ( value )


3. peep operation :-
    If we are interested about any information stored at any locatoin in a stack, finding that information is known as peep operation.
                In this operation we simply move the pointer in the desired location fetch the information associated with that location.

* Algorithm for peep operation:-

Step 1: [check for stack underflow ]
            if  top-i +1<= 0 then     (here i is the position which have to extract)
            output:- "stack is underflow " and exit. 

Step 2: [return the ith element from the top of stack]
            return (S[top-i +1])



4. update operation:-
   Update operation is required when the containt of same location in a stack is to be changed. If we want to update value at ith position in a stack S , we move top pointer to the ith loction from the top of the stack and  input new value of that location.

* Algorithm for update opertaion:-
Step 1: If  top-i +1<= 0  then
          output:- "stack is underflow "  and exit.
Step 2: [Change the element ]
          S[top-i+1] = value.

Comments

Post a Comment

Please comment.

Popular posts from this blog

Process Scheduling And Types of Process Schedular :-

        ⇰ PROCESS SCHEDULING Process Scheduling  is a task  of Operating System that schedules processes of different states like new, ready, waiting, terminated  and running.This scheduling helps in allocation of CPU time for each process, and Operating System allocates the CPU time for each procss. And the process scheduling plays important role to keep the CPU busy all the time.  ⏩   Followings are some objectives of Process Scheduling :-  i > To increase the amount of users within acceptable response times.  ii > To maintain the balance between response and utilization of system. iii > To decrease the enforce priorities and  give reference to the processes holding the key resources.      ⇰  PROCESS SCHEDULAR A scheduler carries out the pro cess scheduling work. Schedulers are often implemented so they keep all computer resources busy and  allows multiple users to share system resources  to achieve  multiprogramming .  There are  mainy three types of pro

Tokens and its types in 'C'

   Tokens are the smallest individual unit of a program or in simple words it is a main part of C program.Tokens are the building blocks of any program. The smallest individual and basic unit of a C programming is called c tokens.      *    Normally there are six types of tokens in C:- i> Keywords:-          Keywords are special words that are used to give a special meaning to the program and can't be used as variable and constant.They are basically a sequence of characters that have fixed to mean. For example:-                 auto     double      long     break                 float    short        char     if                while    continue   int       void etc. All keywords must be written in lower case.It is 32 in number. ii> Identifiers:-         The identifiers are basically a token. It can be a variable's name or a label's name. So identifiers are actually a user defined data. But there are certain rules to frame an identifier. They are as follo

Micromax 'The Indian Smart Phone Company'

Micromax  is an Indian  consumer electronics  company headquartered in  Gurgaon ,  Haryana . It was established as an  IT   Software  company operating in the  Embedded Devices   Domain . It later entered the  Mobile   Handset  business. Micromax was incorporated as Micromax Informatics Ltd. on 29 March 2000 by Zeeshan Ali Zaidi. It began selling mobile telephones in 2008,  focusing on  low pricing to compete with international brands. By 2010, Micromax was one of the largest domestic companies making handsets in the low-cost feature phone segment in India. As of Q3 2014, Micromax is the  Tenth Largest   Smart phone  vendor in the world. The company is facing stiff competition from Chinese companies that are penetrating the Indian market. The company also owns  YU Televentures , which sells its products under the brand name YU. The company has also introduced handsets with innovative features. For instance, Micromax's co-founder  Rahul Sharma  once saw a  public call