Stack Y S N L Srihari
Introduction on Stack Def:  Stack is a collection of similar type of    elements. It is like one side open box, it    is having a property ‘FILO’      (First In Last Out). In stack last inserted element can serve first. Stack is a linear data structure. Stack can be implemented in two way’s, by using arrays and by using linked list.
Operations on Stack Stack can perform two types of operations, those are, Push:   It is a process to insert an element in to    a stack. Pop:   It is a process remove an element from    stack.
Working procedure of a stack Variable ‘TOP’ is used for performing ‘PUSH’ and ‘POP’ operations. Push and Pop an element of stack at the position of a stack.
Stack using arrays Array is a collection of similar type of elements.  Array is a linear data structure. Procedure:  Declare an array for stack, with a maximum size to store elements. Initialize the position value of variable top is ‘-1’. When we push an element into a stack, check the top value, if it reaches the maximum limit or not, if it is not push an element into stack. When we Pop an element from stack, check the top value, if it reaches the ‘-1’or not, if it is not Pop an element from stack.
Push code Step 1: Start. Step 2:If (top<max) true go to step 3 else go to      Step 5. Step 3: Push an element into a stack. Step 4: Increment the value in ‘top’ once.    (top=top+1) go to Step 6: Step 5: Print “push operation is not possible” Step 6: Stop.
Pop code Step 1: Start. Step 2:If (top== -1) true go to step 3 else go to Step 5. Step 3: Pop an element from stack and print value. Step 4: Decrement the value in ‘top’ once. (top=top+1)    go to Step 6: Step 5: Print “Pop operation is not possible” Step 6: Stop.
Diagrammatical representation of Stack   20 10 30 50 Inserting position Removing position
Push and Pop operations Push an element ’45’ into stack Pop an element ’45’ from stack 20 10 30 50 45 20 10 30 50 45 20 10 30 50 45
Stack using linked list When we implement stack using array is having some limitations. The major one is size. In arrays we can push certain number of elements only. To overcome this problem we need linked list. Linked list is a linear data structure. In linked list, each link having two elements, one is data, another one is address of a next link. Linked list can be implemented with the help of pointers. Here the link will be called as node.
Push algorithm using linked list Step 1: Start. Step 2: Create a new node. Step 3: Make a link between last node and new node by Changing the address of last node pointer to new node. Step 4: Set the address of a ‘top’ node as new node. Step 5: Stop. Step 1: Start. Step 2: Remove the link between top and last node of a list. Step 3: Set the address of a ‘top’ node as previous node with the help of a temp node move from starting node to previous node. Step 4: Stop. Pop algorithm using linked list
Example:  Data Address link 10 * 20 * 30 * 40 NULL Top
Push operation:  10 * 20 * 30 * 40 NULL Top New node  45 Null Before Push:  45 Null 10 * 20 * 30 * 40 * Top Step 1:  Step 2:  45 Null 10 * 20 * 30 * 40 * Top
Push operation:  Before Pop:  45 Null 10 * 20 * 30 * 40 Null Top Step 2:  Step 1:  45 Null 10 * 20 * 30 * 40 * Top Temp
Applications of Stack Happstack  ( H askell  App lication  Stack ) is a free application server for websites written in the functional programming language Haskell. It integrates handling Web, persistence, XML/XSLT, and templating functionality . Stack is used by the compiler to compile the program. By using stack C- language compiler can store the special characters like {,},(,),[,]. It can perform checking for each open have a close or not, if it is not rise an error messages. Stack can be used by the operating system to schedule the ‘process’ for processing.
These are used to convert the postfix and prefix notations into infix notations.  Applications of Stack

Stack

  • 1.
    Stack Y SN L Srihari
  • 2.
    Introduction on StackDef: Stack is a collection of similar type of elements. It is like one side open box, it is having a property ‘FILO’ (First In Last Out). In stack last inserted element can serve first. Stack is a linear data structure. Stack can be implemented in two way’s, by using arrays and by using linked list.
  • 3.
    Operations on StackStack can perform two types of operations, those are, Push: It is a process to insert an element in to a stack. Pop: It is a process remove an element from stack.
  • 4.
    Working procedure ofa stack Variable ‘TOP’ is used for performing ‘PUSH’ and ‘POP’ operations. Push and Pop an element of stack at the position of a stack.
  • 5.
    Stack using arraysArray is a collection of similar type of elements. Array is a linear data structure. Procedure: Declare an array for stack, with a maximum size to store elements. Initialize the position value of variable top is ‘-1’. When we push an element into a stack, check the top value, if it reaches the maximum limit or not, if it is not push an element into stack. When we Pop an element from stack, check the top value, if it reaches the ‘-1’or not, if it is not Pop an element from stack.
  • 6.
    Push code Step1: Start. Step 2:If (top<max) true go to step 3 else go to Step 5. Step 3: Push an element into a stack. Step 4: Increment the value in ‘top’ once. (top=top+1) go to Step 6: Step 5: Print “push operation is not possible” Step 6: Stop.
  • 7.
    Pop code Step1: Start. Step 2:If (top== -1) true go to step 3 else go to Step 5. Step 3: Pop an element from stack and print value. Step 4: Decrement the value in ‘top’ once. (top=top+1) go to Step 6: Step 5: Print “Pop operation is not possible” Step 6: Stop.
  • 8.
    Diagrammatical representation ofStack 20 10 30 50 Inserting position Removing position
  • 9.
    Push and Popoperations Push an element ’45’ into stack Pop an element ’45’ from stack 20 10 30 50 45 20 10 30 50 45 20 10 30 50 45
  • 10.
    Stack using linkedlist When we implement stack using array is having some limitations. The major one is size. In arrays we can push certain number of elements only. To overcome this problem we need linked list. Linked list is a linear data structure. In linked list, each link having two elements, one is data, another one is address of a next link. Linked list can be implemented with the help of pointers. Here the link will be called as node.
  • 11.
    Push algorithm usinglinked list Step 1: Start. Step 2: Create a new node. Step 3: Make a link between last node and new node by Changing the address of last node pointer to new node. Step 4: Set the address of a ‘top’ node as new node. Step 5: Stop. Step 1: Start. Step 2: Remove the link between top and last node of a list. Step 3: Set the address of a ‘top’ node as previous node with the help of a temp node move from starting node to previous node. Step 4: Stop. Pop algorithm using linked list
  • 12.
    Example: DataAddress link 10 * 20 * 30 * 40 NULL Top
  • 13.
    Push operation: 10 * 20 * 30 * 40 NULL Top New node 45 Null Before Push: 45 Null 10 * 20 * 30 * 40 * Top Step 1: Step 2: 45 Null 10 * 20 * 30 * 40 * Top
  • 14.
    Push operation: Before Pop: 45 Null 10 * 20 * 30 * 40 Null Top Step 2: Step 1: 45 Null 10 * 20 * 30 * 40 * Top Temp
  • 15.
    Applications of StackHappstack ( H askell App lication Stack ) is a free application server for websites written in the functional programming language Haskell. It integrates handling Web, persistence, XML/XSLT, and templating functionality . Stack is used by the compiler to compile the program. By using stack C- language compiler can store the special characters like {,},(,),[,]. It can perform checking for each open have a close or not, if it is not rise an error messages. Stack can be used by the operating system to schedule the ‘process’ for processing.
  • 16.
    These are usedto convert the postfix and prefix notations into infix notations. Applications of Stack