Explain what is stack. describe ways to execute stack. , Data Structure & Algorithms

 

STACK is explained as follows:

A stack is one of the most usually used data structure. A stack is also called a Last-In-First-Out (LIFO) system, is a linear list in which insertion or deletion can take place only at one end called the top. This structure operates in the identical way as the stack of trays if we want to place another tray, it can be placed only at the top. Likewise, if we want to remove a tray from stack of trays, it can only be removed from the top. The insertion and removal operations in stack terminology are known as PUSH and POP operation.

369_stack.png 

(a)  Stack after the pushing of elements 8,10,12,5,6

(b) Stack after the popping of 2 elements.

Implementation of Stack is explained below

Stacks can be implemented in the below given two ways ways:

a)  Arrays is also implementation of stacks

b)  Linked List is also implementation of stacks

a)  Arrays:- To implement a stack we require a variable called top, that holds the index of the top element of stack and an array to hold the element of the stack.

For example:-     #define MAX 100

Typedef struct

{ int top;

int elements [MAX]

} stack;

b)  Linked List:- A stack represented by making use of a linked list is known as linked stack. The array based representation of stack suffers from the certain limitations.

        Size of stack must be known to us in advance

        Overflow condition may occur.

The linked representation allows a stack to develop to a limit of the computer's memory.

for example:-      typedef struct node

{

int info;

struct node * next;

} stack;

stack * top;

Posted Date: 7/13/2012 1:27:10 AM | Location : United States







Related Discussions:- Explain what is stack. describe ways to execute stack. , Assignment Help, Ask Question on Explain what is stack. describe ways to execute stack. , Get Answer, Expert's Help, Explain what is stack. describe ways to execute stack. Discussions

Write discussion on Explain what is stack. describe ways to execute stack.
Your posts are moderated
Related Questions
Example: (Double left rotation while a new node is added into the AVL tree (RL rotation)) Figure: Double left rotation when a new node is inserted into the AVL tree A

a) Find the shortest paths from r to all other nodes in the digraph G=(V,E) shown below using the Bellman-Ford algorithm (as taught in class). Please show your work, and draw the f

What is Assertions Introduction At every point in a program, there are generally constraints on the computational state that should hold for program to be correct. For ins

since the gregorian calendar was introduced in 1752,a leap year occurs every 4 years.you are to write a pseudo code to find out whether a year is a leap year.your progrm should dis

Readjusting for tree modification calls for rotations in the binary search tree. Single rotations are possible in the left or right direction for moving a node to the root position

Think of a program you have used that is unacceptably slow. Identify the specific operations that make the program slow. Identify other basic operations that the program performs q

A binary search tree is used to locate the number 43. Which of the following probe sequences are possible and which are not? Explain. (a) 61 52 14 17 40 43 (b) 2 3 50 40 60 43 (c)

what is alphanumerical code

Explain the Interfaces in Ruby Recall that in object-oriented programming, an interface is a collection of abstract operations that cannot be instantiated. Even though Ruby i

Implementation of Stack :- Stacks can be executed in the 2 ways: a)  Arrays b)  Linked List