Search this site
Embedded Files
Shaligram Prajapat Ph.D.
  • About Prof
    • Books
  • PI-MCA
  • Projects
    • Academic and Industry Projects
      • Project Topics-2K17
      • April 2012
      • M.Tech. (IT) -Projects@2K17
      • Templates
      • Minor Project
      • Integrated M.Tech. Industry Projects
      • Proposal
    • Synopsis
    • Proposal
    • Samples
    • SIH -Smart India Hackathon
  • Teaching
    • CONM-NAD
    • IC-305C: Data Structures
      • Prerequisite
      • ALGORITHM
        • Deterministic and Non-deterministic Algorithms
      • FUNCTION AND RECURSION
      • ASSINGMENT
      • Stack
      • Queue
      • List
        • Linked Stack
        • Linked Queue
        • Linked Polynomial
        • Linked Sparse Matrix
      • Tree
    • Theory of Computation
      • Overview
      • LO, CO
    • Data Science
      • Data Science - Assignments
      • Data Warehousing and Mining
    • Analysis and Design of Algorithms
    • INFO-SEC
    • SKC-AVK
    • Information System Analysis & Design (SAD )
      • Resources
      • Assignment-21
        • Rubrics
    • Research in Computing
      • Journal-List
      • Conference List
      • Formats
      • Abstract
      • Acknowledgement
      • Areas/Topics
      • Introduction
      • Preliminary Concepts
        • Objective of Research
        • Research Methodology
      • References
      • Research Gap
        • Research methodology
      • Research-Publication
        • Invited Talks
      • results
      • Results/Discussion
      • Title
        • FDP-Workshops
      • Tools and Tips
        • Tips for me-To remember(4 conference)
      • Types of Research
      • Types of Research
      • Publications
      • Research in Computing-MCA-XI semester
        • Template
        • Research-Committee-Member
        • Abstract
        • Research Methodology
    • Computer Graphics-IC-503
    • DigitalElex-2020
      • PPTs Digital Electronics
      • Syllabus of DE
      • Assignments
      • Test/Quiz
    • DCO
    • Discrete Structure
      • Discrete Structure
    • IGNOU
    • Tree Data Strucures
  • SP Research
    • Edited Books
    • Conferences
  • Scholars
  • Events & Activity
    • RC-2020
      • Activity
    • Mentor
  • FDP/Workshops/Short Courses
  • Miscellaneous
    • Invited Talk /Expert Talk
    • My Students
    • My Teachers
  • Publications
  • Recommendations
    • Books
    • ECC- Research Publications
  • Contact me
Shaligram Prajapat Ph.D.
  • About Prof
    • Books
  • PI-MCA
  • Projects
    • Academic and Industry Projects
      • Project Topics-2K17
      • April 2012
      • M.Tech. (IT) -Projects@2K17
      • Templates
      • Minor Project
      • Integrated M.Tech. Industry Projects
      • Proposal
    • Synopsis
    • Proposal
    • Samples
    • SIH -Smart India Hackathon
  • Teaching
    • CONM-NAD
    • IC-305C: Data Structures
      • Prerequisite
      • ALGORITHM
        • Deterministic and Non-deterministic Algorithms
      • FUNCTION AND RECURSION
      • ASSINGMENT
      • Stack
      • Queue
      • List
        • Linked Stack
        • Linked Queue
        • Linked Polynomial
        • Linked Sparse Matrix
      • Tree
    • Theory of Computation
      • Overview
      • LO, CO
    • Data Science
      • Data Science - Assignments
      • Data Warehousing and Mining
    • Analysis and Design of Algorithms
    • INFO-SEC
    • SKC-AVK
    • Information System Analysis & Design (SAD )
      • Resources
      • Assignment-21
        • Rubrics
    • Research in Computing
      • Journal-List
      • Conference List
      • Formats
      • Abstract
      • Acknowledgement
      • Areas/Topics
      • Introduction
      • Preliminary Concepts
        • Objective of Research
        • Research Methodology
      • References
      • Research Gap
        • Research methodology
      • Research-Publication
        • Invited Talks
      • results
      • Results/Discussion
      • Title
        • FDP-Workshops
      • Tools and Tips
        • Tips for me-To remember(4 conference)
      • Types of Research
      • Types of Research
      • Publications
      • Research in Computing-MCA-XI semester
        • Template
        • Research-Committee-Member
        • Abstract
        • Research Methodology
    • Computer Graphics-IC-503
    • DigitalElex-2020
      • PPTs Digital Electronics
      • Syllabus of DE
      • Assignments
      • Test/Quiz
    • DCO
    • Discrete Structure
      • Discrete Structure
    • IGNOU
    • Tree Data Strucures
  • SP Research
    • Edited Books
    • Conferences
  • Scholars
  • Events & Activity
    • RC-2020
      • Activity
    • Mentor
  • FDP/Workshops/Short Courses
  • Miscellaneous
    • Invited Talk /Expert Talk
    • My Students
    • My Teachers
  • Publications
  • Recommendations
    • Books
    • ECC- Research Publications
  • Contact me
  • More
    • About Prof
      • Books
    • PI-MCA
    • Projects
      • Academic and Industry Projects
        • Project Topics-2K17
        • April 2012
        • M.Tech. (IT) -Projects@2K17
        • Templates
        • Minor Project
        • Integrated M.Tech. Industry Projects
        • Proposal
      • Synopsis
      • Proposal
      • Samples
      • SIH -Smart India Hackathon
    • Teaching
      • CONM-NAD
      • IC-305C: Data Structures
        • Prerequisite
        • ALGORITHM
          • Deterministic and Non-deterministic Algorithms
        • FUNCTION AND RECURSION
        • ASSINGMENT
        • Stack
        • Queue
        • List
          • Linked Stack
          • Linked Queue
          • Linked Polynomial
          • Linked Sparse Matrix
        • Tree
      • Theory of Computation
        • Overview
        • LO, CO
      • Data Science
        • Data Science - Assignments
        • Data Warehousing and Mining
      • Analysis and Design of Algorithms
      • INFO-SEC
      • SKC-AVK
      • Information System Analysis & Design (SAD )
        • Resources
        • Assignment-21
          • Rubrics
      • Research in Computing
        • Journal-List
        • Conference List
        • Formats
        • Abstract
        • Acknowledgement
        • Areas/Topics
        • Introduction
        • Preliminary Concepts
          • Objective of Research
          • Research Methodology
        • References
        • Research Gap
          • Research methodology
        • Research-Publication
          • Invited Talks
        • results
        • Results/Discussion
        • Title
          • FDP-Workshops
        • Tools and Tips
          • Tips for me-To remember(4 conference)
        • Types of Research
        • Types of Research
        • Publications
        • Research in Computing-MCA-XI semester
          • Template
          • Research-Committee-Member
          • Abstract
          • Research Methodology
      • Computer Graphics-IC-503
      • DigitalElex-2020
        • PPTs Digital Electronics
        • Syllabus of DE
        • Assignments
        • Test/Quiz
      • DCO
      • Discrete Structure
        • Discrete Structure
      • IGNOU
      • Tree Data Strucures
    • SP Research
      • Edited Books
      • Conferences
    • Scholars
    • Events & Activity
      • RC-2020
        • Activity
      • Mentor
    • FDP/Workshops/Short Courses
    • Miscellaneous
      • Invited Talk /Expert Talk
      • My Students
      • My Teachers
    • Publications
    • Recommendations
      • Books
      • ECC- Research Publications
    • Contact me

Stack Data Structures

A Stack is a linear data structure in which elements are inserted and deleted from one end only, called the TOP. It follows the LIFO (Last In, First Out) principle.
Example: Stack of plates. Stack of books.

Possible Operations:

  • Push: Insert an element onto the TOP of the stack.

  • Pop: Remove an element from the TOP of the stack.

  • Peek/Top: View the TOP element without removing it.

  • isEmpty: Check whether the stack is empty.

  • isFull: Check whether the stack is full in an array-based implementation.

  • Size: Find the number of elements in the stack.

  • Display/Traverse: View all elements of the stack.

  • Search: Find a specified element in the stack.

  • Clear: Remove all elements from the stack.

Delcaration  and Operations

#define MAX 100

typedef struct {

    int data[MAX];

    int top;

} Stack;

void push(Stack *s, int value);

int pop(Stack *s);

int peek(const Stack *s);

int isEmpty(const Stack *s);

int isFull(const Stack *s);

void display(const Stack *s);

MultiStack (n=2)

Two stacks can be implemented efficiently in one array by growing the two stacks from opposite ends of the array.

Two Stacks in a Single Array

Suppose the array has size MAX = 10.

  • Stack 1 grows from left to right.

  • Stack 2 grows from right to left.

  • Both stacks share the unused space in the middle.

  • Overflow occurs when top1 + 1 == top2.

Array: with 2 stacks

+----+----+----+----+----+----+----+----+----+----+--+----+

| S1 | S1 | S1 |    |    |   |   | S2 | S2 | S2 |

+----+----+----+----+----+----+----+----+----+----+--+----+

  ↑                         ↑

 top1                  top2

Initialization

#define MAX 10


int stack[MAX];

int top1 = -1;       // Stack 1

int top2 = MAX;      // Stack 2


PUSH Operation

______________________________


Push into Stack 1

void push1(int value)

{

    if (top1 + 1 == top2)

        printf("Stack Overflow");

    else

        stack[++top1] = value;

}

Push into Stack 2

void push2(int value)

{

    if (top1 + 1 == top2)

        printf("Stack Overflow");

    else

        stack[--top2] = value;

}


POP Operation

______________________________

Pop from Stack 1

int pop1()

{

    if (top1 == -1)

        return -1;


    return stack[top1--];

}

Pop from Stack 2

int pop2()

{

    if (top2 == MAX)

        return -1;


    return stack[top2++];

}

Example

If we perform:

push1(10)

push1(20)

push1(30)


push2(90)

push2(80)

push2(70)

The array becomes:

Index:  0    1    2    3    4    5    6    7    8    9

       +----+----+----+----+----+----+----+----+----+----+

       | 10 | 20 | 30 |    |    |    |    | 70 | 80 | 90 |

       +----+----+----+----+----+----+----+----+----+----+

                   ↑                   ↑

                  top1                top2

Main advantage: The unused space of one stack can be used by the other stack. This reduces wastage compared with allocating two separate fixed-size arrays.

Viva Questions

  1. Why are two stacks implemented from opposite ends?

  2. What is the initial value of top1?

  3. What is the initial value of top2?

  4. What is the condition for overflow?

  5. How does push1() differ from push2()?

  6. How does pop1() differ from pop2()?

  7. What happens when the two stacks meet?

  8. What is the advantage of implementing two stacks in one array?

  9. What is the time complexity of push and pop operations?

  10. Can the two stacks have different numbers of elements? Why?

Applications of Stack

Useful Links :  Research Gate |Linked In | Google Scholar |Web of Science|  ORCID |Scopus ID|Google Site | Vidwan-ID  

Google Sites
Report abuse
Page details
Page updated
Google Sites
Report abuse