Puedes seguirnos en

BUSCADOR

Engineering

Stack as an ADT in Data structure

Stack is a LIFO(Last in first out) structure. Stack can be represented using an one-dimensional array which can hold the elements of a stack. Another variable «top» is used to keep track of the index of the top most element.

Formally, a stack may be defined as follows:

 

typedef struct stack
{
  int data[SIZE];
  int top;

}

Anuncio publicitario

SIZE is a constant, maximum number of elements that can be stored.

Associated with the object stack there are several operations that are necessary:

    1. void initialize(stack *p): It initializes a stack as an empty stack, Initial value of top is set to -1.
    2. int empty(stack *p): Function checks whether the stack is empty. It return 0 or 1 depending on whether the stack is empty or not.
    3. int full(stack *p): This function checks whether the stack is full. A stack is said to be full when the associated array is completely filled up. Whenever the stack is full, top points to the last element of the array. This function returns 1 or 0 depending on whether the stack is full or not.
    4. int pop(stack *p): This function deletes topmost element from the stack and also returns it to the calling program. Deletion from an empty stack will cause underflow.

  1. void push(stack *p, int x): The function inserts the element x onto the stack pointed by P. Insertion will cause an overflow if the stack is full.

Escrito por

Administrador de ENGGDRCAOS. Canal dedicado especialmente a la formación del estudiante que aspira a ser ingeniero. Todos los videos son Ingles. Apasionado del universo Apple, estudiante de Ingeniería y Gamer por vocación.

Publicidad

ARTÍCULOS RELACIONADOS

Engineering

Interrupt is a signal sent to the processor by a software or an hardware, which has a high priority. An interrupt causes the microprocessor...

Engineering

Singly linked list is a dynamically allocated list, which consists of one or more nodes. Each node contains a pointer which holds the address...

Engineering

Singly linked list is a type of list which uses dynamic representation rather than a much simpler and versatile static representation. Dynamic representation is...

Engineering

The 8085 microprocessor was a beast when it was released. It was an 8 bit microprocessor which could access a total on 64Kb of...